Skip to content

Matrix2D

何波 edited this page Feb 22, 2019 · 7 revisions

append(a, b, c, d, tx, ty)

将指定的矩阵属性附加到此矩阵,这相当于乘以(此矩阵)*(指定矩阵)

prepend(a, b, c, d, tx, ty)

Prepends the specified matrix properties to this matrix.这相当于乘以(指定矩阵)*(此矩阵)

appendMatrix(matrix) 与append一样

p.appendMatrix = function(matrix) {
    return this.append(matrix.a, matrix.b, matrix.c, matrix.d, matrix.tx, matrix.ty);
};

prependMatrix(matrix) 与prepend一样

p.prependMatrix = function(matrix) {
    return this.prepend(matrix.a, matrix.b, matrix.c, matrix.d, matrix.tx, matrix.ty);
};

appendTransform(x, y, scaleX, scaleY, rotation, skewX, skewY, regX, regY)

从指定的显示对象转换属性生成矩阵属性,并将其附加到此矩阵。非常有用

function demo1 () {
  let box = game.add.box(100, 100, 'red', {
    x: 100,
    y: 100,
    rotation: 60
  })
  console.info(box)
  let mtx = new createjs.Matrix2D()
  // 把box的位置信息转换成一个Matrix2D,并append到当前的Matrix2D上
  let resMtx = mtx.appendTransform(box.x, box.y, box.scaleX, box.scaleY, box.rotation)
  console.info(resMtx)

  let box2 = game.add.box(50, 50, 'blue')
  // 现在box2会用box的矩阵变换
  // box2.transformMatrix = resMtx

  // 或直接获取box的matrix
  box2.transformMatrix = box.getMatrix()
}

Clone this wiki locally