Matrix2D Class
Represents an affine transformation matrix, and provides tools for constructing and concatenating matrices.
This matrix can be visualized as:
[ a c tx
b d ty
0 0 1 ]
Note the locations of b and c.
Constructor
Matrix2D
-
[a=1]
-
[b=0]
-
[c=0]
-
[d=1]
-
[tx=0]
-
[ty=0]
Parameters:
-
[a=1]
Number optionalSpecifies the a property for the new matrix.
-
[b=0]
Number optionalSpecifies the b property for the new matrix.
-
[c=0]
Number optionalSpecifies the c property for the new matrix.
-
[d=1]
Number optionalSpecifies the d property for the new matrix.
-
[tx=0]
Number optionalSpecifies the tx property for the new matrix.
-
[ty=0]
Number optionalSpecifies the ty property for the new matrix.
Item Index
Methods
Methods
append
-
a
-
b
-
c
-
d
-
tx
-
ty
Appends the specified matrix properties to this matrix. All parameters are required.
This is the equivalent of multiplying (this matrix) * (specified matrix)
.
Returns:
This matrix. Useful for chaining method calls.
appendMatrix
-
matrix
Appends the specified matrix to this matrix.
This is the equivalent of multiplying (this matrix) * (specified matrix)
.
Parameters:
-
matrix
Matrix2D
Returns:
This matrix. Useful for chaining method calls.
appendTransform
-
x
-
y
-
scaleX
-
scaleY
-
rotation
-
skewX
-
skewY
-
regX
-
regY
Generates matrix properties from the specified display object transform properties, and appends them to this matrix. For example, you can use this to generate a matrix representing the transformations of a display object:
var mtx = new createjs.Matrix2D();
mtx.appendTransform(o.x, o.y, o.scaleX, o.scaleY, o.rotation);
Parameters:
Returns:
This matrix. Useful for chaining method calls.
clone
()
Matrix2D
Returns a clone of the Matrix2D instance.
Returns:
a clone of the Matrix2D instance.
copy
-
matrix
Copies all properties from the specified matrix to this matrix.
Parameters:
-
matrix
Matrix2DThe matrix to copy properties from.
Returns:
This matrix. Useful for chaining method calls.
decompose
-
target
Decomposes the matrix into transform properties (x, y, scaleX, scaleY, and rotation). Note that these values may not match the transform properties you used to generate the matrix, though they will produce the same visual results.
Parameters:
-
target
ObjectThe object to apply the transform properties to. If null, then a new object will be returned.
Returns:
The target, or a new generic object with the transform properties applied.
equals
-
matrix
Returns true if this matrix is equal to the specified matrix (all property values are equal).
Parameters:
-
matrix
Matrix2DThe matrix to compare.
Returns:
identity
()
Matrix2D
Sets the properties of the matrix to those of an identity matrix (one that applies a null transformation).
Returns:
This matrix. Useful for chaining method calls.
invert
()
Matrix2D
Inverts the matrix, causing it to perform the opposite transformation.
Returns:
This matrix. Useful for chaining method calls.
prepend
-
a
-
b
-
c
-
d
-
tx
-
ty
Prepends the specified matrix properties to this matrix.
This is the equivalent of multiplying (specified matrix) * (this matrix)
.
All parameters are required.
Returns:
This matrix. Useful for chaining method calls.
prependMatrix
-
matrix
Prepends the specified matrix to this matrix.
This is the equivalent of multiplying (specified matrix) * (this matrix)
.
For example, you could calculate the combined transformation for a child object using:
var o = myDisplayObject;
var mtx = o.getMatrix();
while (o = o.parent) {
// prepend each parent's transformation in turn:
o.prependMatrix(o.getMatrix());
}
Parameters:
-
matrix
Matrix2D
Returns:
This matrix. Useful for chaining method calls.
prependTransform
-
x
-
y
-
scaleX
-
scaleY
-
rotation
-
skewX
-
skewY
-
regX
-
regY
Generates matrix properties from the specified display object transform properties, and prepends them to this matrix. For example, you could calculate the combined transformation for a child object using:
var o = myDisplayObject;
var mtx = new createjs.Matrix2D();
do {
// prepend each parent's transformation in turn:
mtx.prependTransform(o.x, o.y, o.scaleX, o.scaleY, o.rotation, o.skewX, o.skewY, o.regX, o.regY);
} while (o = o.parent);
Note that the above example would not account for transformMatrix
values. See prependMatrix for an example that does.
Parameters:
Returns:
This matrix. Useful for chaining method calls.
rotate
-
angle
Applies a clockwise rotation transformation to the matrix.
Parameters:
-
angle
NumberThe angle to rotate by, in degrees. To use a value in radians, multiply it by
180/Math.PI
.
Returns:
This matrix. Useful for chaining method calls.
scale
-
x
-
y
Applies a scale transformation to the matrix.
Parameters:
Returns:
This matrix. Useful for chaining method calls.
setValues
-
[a=1]
-
[b=0]
-
[c=0]
-
[d=1]
-
[tx=0]
-
[ty=0]
Sets the specified values on this instance.
Parameters:
-
[a=1]
Number optionalSpecifies the a property for the new matrix.
-
[b=0]
Number optionalSpecifies the b property for the new matrix.
-
[c=0]
Number optionalSpecifies the c property for the new matrix.
-
[d=1]
Number optionalSpecifies the d property for the new matrix.
-
[tx=0]
Number optionalSpecifies the tx property for the new matrix.
-
[ty=0]
Number optionalSpecifies the ty property for the new matrix.
Returns:
This instance. Useful for chaining method calls.
skew
-
skewX
-
skewY
Applies a skew transformation to the matrix.
Parameters:
Returns:
This matrix. Useful for chaining method calls.
toString
()
String
Returns a string representation of this object.
Returns:
a string representation of the instance.
Properties
DEG_TO_RAD
Number
final
static
readonly
Multiplier for converting degrees to radians. Used internally by Matrix2D.