Transformations helper class to store 2d position, rotation and scale. Can also perform transformations inheritance, where we combine local with parent transformations.
Number
Combine child scalar value with parent using a transformation mode.
Vector2
Combine child vector value with parent using a transformation mode.
Vector2
Combine child vector value with parent using a transformation mode and multiplication.
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
function
Vector2
TransformModes
Transformation
Transformation
Transformation
Transformation
Transformation
Vector2
TransformModes
Transformation
Transformation
Transformation
Transformation
Transformation
Number
Number
Number
TransformModes
Transformation
Transformation
Transformation
Transformation
Transformation
Boolean
Transformation
Matrix
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();
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
Vector2
Get position.
Kind: instance method of Transformation
Returns: Vector2
- Position.
TransformModes
Get position transformations mode.
Kind: instance method of Transformation
Returns: TransformModes
- Position transformation mode.
Transformation
Set position.
Kind: instance method of Transformation
Returns: Transformation
- this.
Param | Type | Description |
---|---|---|
value | Vector2 |
New position. |
Transformation
Set position X value.
Kind: instance method of Transformation
Returns: Transformation
- this.
Param | Type | Description |
---|---|---|
value | Number |
New position.x 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 position by a given vector.
Kind: instance method of Transformation
Returns: Transformation
- this.
Param | Type | Description |
---|---|---|
value | Vector2 |
Vector to move position by. |
Transformation
Set position transformations mode.
Kind: instance method of Transformation
Returns: Transformation
- this.
Param | Type | Description |
---|---|---|
value | TransformModes |
Position transformation mode. |
Vector2
Get scale.
Kind: instance method of Transformation
Returns: Vector2
- Scale.
TransformModes
Get scale transformations mode.
Kind: instance method of Transformation
Returns: TransformModes
- Scale transformation mode.
Transformation
Set scale.
Kind: instance method of Transformation
Returns: Transformation
- this.
Param | Type | Description |
---|---|---|
value | Vector2 |
New scale. |
Transformation
Set scale X value.
Kind: instance method of Transformation
Returns: Transformation
- this.
Param | Type | Description |
---|---|---|
value | Number |
New scale.x 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 by a given vector.
Kind: instance method of Transformation
Returns: Transformation
- this.
Param | Type | Description |
---|---|---|
value | Vector2 |
Vector to scale by. |
Transformation
Set scale transformations mode.
Kind: instance method of Transformation
Returns: Transformation
- this.
Param | Type | Description |
---|---|---|
value | TransformModes |
Scale transformation mode. |
Number
Get rotation.
Kind: instance method of Transformation
Returns: Number
- rotation.
Number
Get rotation as degrees.
Kind: instance method of Transformation
Returns: Number
- rotation.
Number
Get rotation as degrees, wrapped between 0 to 360.
Kind: instance method of Transformation
Returns: Number
- rotation.
TransformModes
Get rotation transformations mode.
Kind: instance method of Transformation
Returns: TransformModes
- Rotation transformations mode.
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 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
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
Rotate transformation by given degrees.
Kind: instance method of Transformation
Returns: Transformation
- this.
Param | Type | Description |
---|---|---|
value | Number |
Rotate value in degrees. |
Transformation
Set rotation transformations mode.
Kind: instance method of Transformation
Returns: Transformation
- this.
Param | Type | Description |
---|---|---|
value | TransformModes |
Rotation transformation mode. |
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
Return a clone of this transformations.
Kind: instance method of Transformation
Returns: Transformation
- Cloned transformations.
Serialize this transformation into a dictionary.
Kind: instance method of Transformation
Deserialize this transformation from a dictionary.
Kind: instance method of Transformation
Param | Type | Description |
---|---|---|
data | \* |
Data to set. |
Matrix
Create and return a transformation matrix.
Kind: instance method of Transformation
Returns: Matrix
- New transformation matrix.
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. |
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. |
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. |
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. |