Shaku

Shaku JS

Back To Table of Content

Transformation

Classes

Transformation

Transformations helper class to store 2d position, rotation and scale. Can also perform transformations inheritance, where we combine local with parent transformations.

Functions

combineScalar(childValue, parentValue, parent, mode)Number

Combine child scalar value with parent using a transformation mode.

combineVector(childValue, parentValue, parent, mode)Vector2

Combine child vector value with parent using a transformation mode.

combineVectorMul(childValue, parentValue, parent, mode)Vector2

Combine child vector value with parent using a transformation mode and multiplication.

Transformation

Transformations helper class to store 2d position, rotation and scale. Can also perform transformations inheritance, where we combine local with parent transformations.

Kind: global class

new Transformation(position, rotation, scale)

Create the transformations.

Param Type Description
position Vector2 Optional position value.
rotation Number Optional rotation value.
scale Vector2 Optional sscale value.

Example

// create local and world transformations
const transform = new Shaku.utils.Transformation();
const worldTransform = new Shaku.utils.Transformation();
// set offset to world transofm and rotation to local transform
worldTransform.setPosition({x: 100, y:50});
transform.setRotation(5);
// combine transformations and convert to a matrix
const combined = Shaku.utils.Transformation.combine(transform, worldTransform);
const matrix = combined.asMatrix();

transformation.onChange : function

Method to call when this transformation change. Function params: transformation instance (this), properties changed (boolean), transform modes changed (boolean).

Kind: instance property of Transformation

transformation.getPosition() ⇒ Vector2

Get position.

Kind: instance method of Transformation
Returns: Vector2 - Position.

transformation.getPositionMode() ⇒ TransformModes

Get position transformations mode.

Kind: instance method of Transformation
Returns: TransformModes - Position transformation mode.

transformation.setPosition(value) ⇒ Transformation

Set position.

Kind: instance method of Transformation
Returns: Transformation - this.

Param Type Description
value Vector2 New position.

transformation.setPositionX(value) ⇒ Transformation

Set position X value.

Kind: instance method of Transformation
Returns: Transformation - this.

Param Type Description
value Number New position.x value.

transformation.setPositionY(value) ⇒ Transformation

Set position Y value.

Kind: instance method of Transformation
Returns: Transformation - this.

Param Type Description
value Number New position.y value.

transformation.move(value) ⇒ Transformation

Move position by a given vector.

Kind: instance method of Transformation
Returns: Transformation - this.

Param Type Description
value Vector2 Vector to move position by.

transformation.setPositionMode(value) ⇒ Transformation

Set position transformations mode.

Kind: instance method of Transformation
Returns: Transformation - this.

Param Type Description
value TransformModes Position transformation mode.

transformation.getScale() ⇒ Vector2

Get scale.

Kind: instance method of Transformation
Returns: Vector2 - Scale.

transformation.getScaleMode() ⇒ TransformModes

Get scale transformations mode.

Kind: instance method of Transformation
Returns: TransformModes - Scale transformation mode.

transformation.setScale(value) ⇒ Transformation

Set scale.

Kind: instance method of Transformation
Returns: Transformation - this.

Param Type Description
value Vector2 New scale.

transformation.setScaleX(value) ⇒ Transformation

Set scale X value.

Kind: instance method of Transformation
Returns: Transformation - this.

Param Type Description
value Number New scale.x value.

transformation.setScaleY(value) ⇒ Transformation

Set scale Y value.

Kind: instance method of Transformation
Returns: Transformation - this.

Param Type Description
value Number New scale.y value.

transformation.scale(value) ⇒ Transformation

Scale by a given vector.

Kind: instance method of Transformation
Returns: Transformation - this.

Param Type Description
value Vector2 Vector to scale by.

transformation.setScaleMode(value) ⇒ Transformation

Set scale transformations mode.

Kind: instance method of Transformation
Returns: Transformation - this.

Param Type Description
value TransformModes Scale transformation mode.

transformation.getRotation() ⇒ Number

Get rotation.

Kind: instance method of Transformation
Returns: Number - rotation.

transformation.getRotationDegrees() ⇒ Number

Get rotation as degrees.

Kind: instance method of Transformation
Returns: Number - rotation.

transformation.getRotationDegreesWrapped() ⇒ Number

Get rotation as degrees, wrapped between 0 to 360.

Kind: instance method of Transformation
Returns: Number - rotation.

transformation.getRotationMode() ⇒ TransformModes

Get rotation transformations mode.

Kind: instance method of Transformation
Returns: TransformModes - Rotation transformations mode.

transformation.setRotation(value, wrap) ⇒ Transformation

Set rotation.

Kind: instance method of Transformation
Returns: Transformation - this.

Param Type Description
value Number New rotation.
wrap Boolean If true, will wrap value if out of possible range.

transformation.rotate(value, wrap) ⇒ Transformation

Rotate transformation by given radians.

Kind: instance method of Transformation
Returns: Transformation - this.

Param Type Description
value Number Rotate value in radians.
wrap Boolean If true, will wrap value if out of possible range.

transformation.setRotationDegrees(value, wrap) ⇒ Transformation

Set rotation as degrees.

Kind: instance method of Transformation
Returns: Transformation - this.

Param Type Description
value Number New rotation.
wrap Boolean If true, will wrap value if out of possible range.

transformation.rotateDegrees(value) ⇒ Transformation

Rotate transformation by given degrees.

Kind: instance method of Transformation
Returns: Transformation - this.

Param Type Description
value Number Rotate value in degrees.

transformation.setRotationMode(value) ⇒ Transformation

Set rotation transformations mode.

Kind: instance method of Transformation
Returns: Transformation - this.

Param Type Description
value TransformModes Rotation transformation mode.

transformation.equals(other) ⇒ Boolean

Check if this transformation equals another.

Kind: instance method of Transformation
Returns: Boolean - True if equal, false otherwise.

Param Type Description
other Transformation Other transform to compare to.

transformation.clone() ⇒ Transformation

Return a clone of this transformations.

Kind: instance method of Transformation
Returns: Transformation - Cloned transformations.

transformation.serialize()

Serialize this transformation into a dictionary.

Kind: instance method of Transformation

transformation.deserialize(data)

Deserialize this transformation from a dictionary.

Kind: instance method of Transformation

Param Type Description
data \* Data to set.

transformation.asMatrix() ⇒ Matrix

Create and return a transformation matrix.

Kind: instance method of Transformation
Returns: Matrix - New transformation matrix.

Transformation.combine(child, parent) ⇒ Transformation

Combine child transformations with parent transformations.

Kind: static method of Transformation
Returns: Transformation - Combined transformations.

Param Type Description
child Transformation Child transformations.
parent Transformation Parent transformations.

combineScalar(childValue, parentValue, parent, mode) ⇒ Number

Combine child scalar value with parent using a transformation mode.

Kind: global function
Returns: Number - Combined value.

Param Type Description
childValue Number Child value.
parentValue Number Parent value.
parent Transformation Parent transformations.
mode TransformModes Transformation mode.

combineVector(childValue, parentValue, parent, mode) ⇒ Vector2

Combine child vector value with parent using a transformation mode.

Kind: global function
Returns: Vector2 - Combined value.

Param Type Description
childValue Vector2 Child value.
parentValue Vector2 Parent value.
parent Transformation Parent transformations.
mode TransformModes Transformation mode.

combineVectorMul(childValue, parentValue, parent, mode) ⇒ Vector2

Combine child vector value with parent using a transformation mode and multiplication.

Kind: global function
Returns: Vector2 - Combined value.

Param Type Description
childValue Vector2 Child value.
parentValue Vector2 Parent value.
parent Transformation Parent transformations.
mode TransformModes Transformation mode.