Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Matrix2D

2×2行列

Hierarchy

  • Matrix2D

Index

Constructors

constructor

  • new Matrix2D(a?: number, b?: number, c?: number, d?: number, tx?: number, ty?: number): Matrix2D
  • 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.

    class

    Matrix2D

    constructor

    Parameters

    • Default value a: number = 1
    • Default value b: number = 0
    • Default value c: number = 0
    • Default value d: number = 1
    • Default value tx: number = 0
    • Default value ty: number = 0

    Returns Matrix2D

Properties

a

a: number

Position (0, 0) in a 3x3 affine transformation matrix.

property

a

type

Number

b

b: number

Position (0, 1) in a 3x3 affine transformation matrix.

property

b

type

Number

c

c: number

Position (1, 0) in a 3x3 affine transformation matrix.

property

c

type

Number

d

d: number

Position (1, 1) in a 3x3 affine transformation matrix.

property

d

type

Number

tx

tx: number

Position (2, 0) in a 3x3 affine transformation matrix.

property

tx

type

Number

ty

ty: number

Position (2, 1) in a 3x3 affine transformation matrix.

property

ty

type

Number

Methods

append

  • append(a: any, b: any, c: any, d: any, tx: any, ty: any): this
  • Appends the specified matrix properties to this matrix. All parameters are required. This is the equivalent of multiplying (this matrix) * (specified matrix).

    method

    append

    Parameters

    • a: any
    • b: any
    • c: any
    • d: any
    • tx: any
    • ty: any

    Returns this

    This matrix. Useful for chaining method calls.

appendMatrix

  • Appends the specified matrix to this matrix. This is the equivalent of multiplying (this matrix) * (specified matrix).

    method

    appendMatrix

    Parameters

    Returns this

    This matrix. Useful for chaining method calls.

appendTransform

  • appendTransform(x: any, y: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any, regX: any, regY: any): this
  • 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 Matrix2D();
    mtx.appendTransform(o.x, o.y, o.scaleX, o.scaleY, o.rotation);
    
    method

    appendTransform

    Parameters

    • x: any
    • y: any
    • scaleX: any
    • scaleY: any
    • rotation: any
    • skewX: any
    • skewY: any
    • regX: any

      Optional.

    • regY: any

      Optional.

    Returns this

    This matrix. Useful for chaining method calls.

clone

  • Returns a clone of the Matrix2D instance.

    method

    clone

    Returns Matrix2D

    a clone of the Matrix2D instance.

copy

  • Copies all properties from the specified matrix to this matrix.

    method

    copy

    Parameters

    • matrix: Matrix2D

      The matrix to copy properties from.

    Returns this

    This matrix. Useful for chaining method calls.

decompose

  • decompose(target: any): any
  • 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.

    method

    decompose

    Parameters

    • target: any

      The object to apply the transform properties to. If null, then a new object will be returned.

    Returns any

    The target, or a new generic object with the transform properties applied.

equals

  • Returns true if this matrix is equal to the specified matrix (all property values are equal).

    method

    equals

    Parameters

    • matrix: Matrix2D

      The matrix to compare.

    Returns boolean

identity

  • identity(): this
  • Sets the properties of the matrix to those of an identity matrix (one that applies a null transformation).

    method

    identity

    Returns this

    This matrix. Useful for chaining method calls.

invert

  • invert(): this
  • Inverts the matrix, causing it to perform the opposite transformation.

    method

    invert

    Returns this

    This matrix. Useful for chaining method calls.

isIdentity

  • isIdentity(): boolean
  • Returns true if the matrix is an identity matrix.

    method

    isIdentity

    Returns boolean

prepend

  • prepend(a: any, b: any, c: any, d: any, tx: any, ty: any): this
  • Prepends the specified matrix properties to this matrix. This is the equivalent of multiplying (specified matrix) * (this matrix). All parameters are required.

    method

    prepend

    Parameters

    • a: any
    • b: any
    • c: any
    • d: any
    • tx: any
    • ty: any

    Returns this

    This matrix. Useful for chaining method calls.

prependMatrix

  • 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());
    }
    
    method

    prependMatrix

    Parameters

    Returns this

    This matrix. Useful for chaining method calls.

prependTransform

  • prependTransform(x: any, y: any, scaleX: any, scaleY: any, rotation: any, skewX: any, skewY: any, regX: any, regY: any): this
  • 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 {{#crossLink "DisplayObject/transformMatrix:property"}}{{/crossLink}}
    values. See {{#crossLink "Matrix2D/prependMatrix"}}{{/crossLink}} for an example that does.
    
    method

    prependTransform

    Parameters

    • x: any
    • y: any
    • scaleX: any
    • scaleY: any
    • rotation: any
    • skewX: any
    • skewY: any
    • regX: any

      Optional.

    • regY: any

      Optional.

    Returns this

    This matrix. Useful for chaining method calls.

rotate

  • rotate(angle: any): this
  • Applies a clockwise rotation transformation to the matrix.

    method

    rotate

    Parameters

    • angle: any

      The angle to rotate by, in degrees. To use a value in radians, multiply it by 180/Math.PI.

    Returns this

    This matrix. Useful for chaining method calls.

scale

  • scale(x: any, y: any): this
  • Applies a scale transformation to the matrix.

    method

    scale

    Parameters

    • x: any

      The amount to scale horizontally. E.G. a value of 2 will double the size in the X direction, and 0.5 will halve it.

    • y: any

      The amount to scale vertically.

    Returns this

    This matrix. Useful for chaining method calls.

setValues

  • setValues(a: any, b: any, c: any, d: any, tx: any, ty: any): this
  • Sets the specified values on this instance.

    method

    setValues

    Parameters

    • a: any
    • b: any
    • c: any
    • d: any
    • tx: any
    • ty: any

    Returns this

    This instance. Useful for chaining method calls.

skew

  • skew(skewX: any, skewY: any): this
  • Applies a skew transformation to the matrix.

    method

    skew

    Parameters

    • skewX: any

      The amount to skew horizontally in degrees. To use a value in radians, multiply it by 180/Math.PI.

    • skewY: any

      The amount to skew vertically in degrees.

    Returns this

    This matrix. Useful for chaining method calls.

toString

  • toString(): string
  • Returns a string representation of this object.

    method

    toString

    Returns string

    a string representation of the instance.

transformPoint

  • Transforms a point according to this matrix.

    method

    transformPoint

    Parameters

    • x: any

      The x component of the point to transform.

    • y: any

      The y component of the point to transform.

    • Optional pt: Point2D

    Returns Point2D

    This matrix. Useful for chaining method calls.

translate

  • translate(x: any, y: any): this
  • Translates the matrix on the x and y axes.

    method

    translate

    Parameters

    • x: any
    • y: any

    Returns this

    This matrix. Useful for chaining method calls.

Generated using TypeDoc