2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2017-07-04 00:59:31 +00:00
|
|
|
var MATH_CONST = require('../../math/const');
|
2018-04-11 12:17:26 +00:00
|
|
|
var TransformMatrix = require('./TransformMatrix');
|
2017-07-04 00:59:31 +00:00
|
|
|
var WrapAngle = require('../../math/angle/Wrap');
|
|
|
|
var WrapAngleDegrees = require('../../math/angle/WrapDegrees');
|
2017-02-23 03:10:48 +00:00
|
|
|
|
2017-02-24 01:45:15 +00:00
|
|
|
// global bitmask flag for GameObject.renderMask (used by Scale)
|
2017-02-23 03:10:48 +00:00
|
|
|
var _FLAG = 4; // 0100
|
|
|
|
|
2018-02-01 00:50:15 +00:00
|
|
|
/**
|
|
|
|
* Provides methods used for getting and setting the position, scale and rotation of a Game Object.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-02-01 00:50:15 +00:00
|
|
|
* @name Phaser.GameObjects.Components.Transform
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-02-23 03:10:48 +00:00
|
|
|
|
|
|
|
var Transform = {
|
|
|
|
|
2018-03-29 12:48:14 +00:00
|
|
|
/**
|
|
|
|
* Private internal value. Holds the horizontal scale value.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Transform#_scaleX
|
2018-06-26 22:19:14 +00:00
|
|
|
* @type {number}
|
2018-03-29 12:48:14 +00:00
|
|
|
* @private
|
|
|
|
* @default 1
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-02-24 01:45:15 +00:00
|
|
|
_scaleX: 1,
|
2018-03-29 12:48:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Private internal value. Holds the vertical scale value.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Transform#_scaleY
|
2018-06-26 22:19:14 +00:00
|
|
|
* @type {number}
|
2018-03-29 12:48:14 +00:00
|
|
|
* @private
|
|
|
|
* @default 1
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-02-24 01:45:15 +00:00
|
|
|
_scaleY: 1,
|
2018-03-29 12:48:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Private internal value. Holds the rotation value in radians.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Components.Transform#_rotation
|
2018-06-26 22:19:14 +00:00
|
|
|
* @type {number}
|
2018-03-29 12:48:14 +00:00
|
|
|
* @private
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-02-24 01:45:15 +00:00
|
|
|
_rotation: 0,
|
2017-02-23 03:10:48 +00:00
|
|
|
|
2018-02-01 00:50:15 +00:00
|
|
|
/**
|
|
|
|
* The x position of this Game Object.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-02-01 00:50:15 +00:00
|
|
|
* @name Phaser.GameObjects.Components.Transform#x
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
x: 0,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The y position of this Game Object.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-02-01 00:50:15 +00:00
|
|
|
* @name Phaser.GameObjects.Components.Transform#y
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
y: 0,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The z position of this Game Object.
|
|
|
|
* Note: Do not use this value to set the z-index, instead see the `depth` property.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-02-01 00:50:15 +00:00
|
|
|
* @name Phaser.GameObjects.Components.Transform#z
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
z: 0,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The w position of this Game Object.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-02-01 00:50:15 +00:00
|
|
|
* @name Phaser.GameObjects.Components.Transform#w
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
w: 0,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The horizontal scale of this Game Object.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-02-01 00:50:15 +00:00
|
|
|
* @name Phaser.GameObjects.Components.Transform#scaleX
|
|
|
|
* @type {number}
|
|
|
|
* @default 1
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-02-23 03:10:48 +00:00
|
|
|
scaleX: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
2017-02-24 01:45:15 +00:00
|
|
|
return this._scaleX;
|
2017-02-23 03:10:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
2017-02-24 01:45:15 +00:00
|
|
|
this._scaleX = value;
|
2017-02-23 03:10:48 +00:00
|
|
|
|
2017-02-24 01:45:15 +00:00
|
|
|
if (this._scaleX === 0)
|
2017-02-23 03:10:48 +00:00
|
|
|
{
|
|
|
|
this.renderFlags &= ~_FLAG;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.renderFlags |= _FLAG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2018-02-01 00:50:15 +00:00
|
|
|
/**
|
|
|
|
* The vertical scale of this Game Object.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-02-01 00:50:15 +00:00
|
|
|
* @name Phaser.GameObjects.Components.Transform#scaleY
|
|
|
|
* @type {number}
|
|
|
|
* @default 1
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-02-23 03:10:48 +00:00
|
|
|
scaleY: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
2017-02-24 01:45:15 +00:00
|
|
|
return this._scaleY;
|
2017-02-23 03:10:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
2017-02-24 01:45:15 +00:00
|
|
|
this._scaleY = value;
|
2017-02-23 03:10:48 +00:00
|
|
|
|
2017-02-24 01:45:15 +00:00
|
|
|
if (this._scaleY === 0)
|
2017-02-23 03:10:48 +00:00
|
|
|
{
|
|
|
|
this.renderFlags &= ~_FLAG;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.renderFlags |= _FLAG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2018-02-01 00:50:15 +00:00
|
|
|
/**
|
|
|
|
* The angle of this Game Object as expressed in degrees.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-02-01 00:50:15 +00:00
|
|
|
* Where 0 is to the right, 90 is down, 180 is left.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-02-01 00:50:15 +00:00
|
|
|
* If you prefer to work in radians, see the `rotation` property instead.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-02-01 00:50:15 +00:00
|
|
|
* @name Phaser.GameObjects.Components.Transform#angle
|
|
|
|
* @type {integer}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-02-24 01:45:15 +00:00
|
|
|
angle: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return WrapAngleDegrees(this._rotation * MATH_CONST.RAD_TO_DEG);
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
// value is in degrees
|
|
|
|
this.rotation = WrapAngleDegrees(value) * MATH_CONST.DEG_TO_RAD;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-02-01 00:50:15 +00:00
|
|
|
/**
|
|
|
|
* The angle of this Game Object in radians.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-02-01 00:50:15 +00:00
|
|
|
* If you prefer to work in degrees, see the `angle` property instead.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-02-01 00:50:15 +00:00
|
|
|
* @name Phaser.GameObjects.Components.Transform#rotation
|
|
|
|
* @type {number}
|
|
|
|
* @default 1
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-02-24 01:45:15 +00:00
|
|
|
rotation: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this._rotation;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
// value is in radians
|
|
|
|
this._rotation = WrapAngle(value);
|
2017-12-15 04:08:25 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-02-01 00:50:15 +00:00
|
|
|
/**
|
|
|
|
* Sets the position of this Game Object.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-02-01 01:36:52 +00:00
|
|
|
* @method Phaser.GameObjects.Components.Transform#setPosition
|
2018-02-01 00:50:15 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {number} [x=0] - The x position of this Game Object.
|
2018-04-05 12:51:37 +00:00
|
|
|
* @param {number} [y=x] - The y position of this Game Object. If not set it will use the `x` value.
|
2018-02-01 00:50:15 +00:00
|
|
|
* @param {number} [z=0] - The z position of this Game Object.
|
|
|
|
* @param {number} [w=0] - The w position of this Game Object.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-05-22 04:46:26 +00:00
|
|
|
* @return {this} This Game Object instance.
|
2018-02-01 00:50:15 +00:00
|
|
|
*/
|
2017-09-15 03:04:51 +00:00
|
|
|
setPosition: function (x, y, z, w)
|
2017-02-23 03:10:48 +00:00
|
|
|
{
|
2017-03-09 00:41:21 +00:00
|
|
|
if (x === undefined) { x = 0; }
|
2017-02-23 03:10:48 +00:00
|
|
|
if (y === undefined) { y = x; }
|
2017-09-15 03:04:51 +00:00
|
|
|
if (z === undefined) { z = 0; }
|
|
|
|
if (w === undefined) { w = 0; }
|
2017-02-23 03:10:48 +00:00
|
|
|
|
2018-02-01 00:50:15 +00:00
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
this.z = z;
|
|
|
|
this.w = w;
|
2017-02-23 03:10:48 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-05-15 14:58:53 +00:00
|
|
|
/**
|
|
|
|
* Sets the position of this Game Object to be a random position within the confines of
|
|
|
|
* the given area.
|
|
|
|
*
|
|
|
|
* If no area is specified a random position between 0 x 0 and the game width x height is used instead.
|
|
|
|
*
|
|
|
|
* The position does not factor in the size of this Game Object, meaning that only the origin is
|
|
|
|
* guaranteed to be within the area.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.Transform#setRandomPosition
|
|
|
|
* @since 3.8.0
|
|
|
|
*
|
|
|
|
* @param {number} [x=0] - The x position of the top-left of the random area.
|
|
|
|
* @param {number} [y=0] - The y position of the top-left of the random area.
|
|
|
|
* @param {number} [width] - The width of the random area.
|
|
|
|
* @param {number} [height] - The height of the random area.
|
|
|
|
*
|
2018-05-22 04:46:26 +00:00
|
|
|
* @return {this} This Game Object instance.
|
2018-05-15 14:58:53 +00:00
|
|
|
*/
|
|
|
|
setRandomPosition: function (x, y, width, height)
|
|
|
|
{
|
|
|
|
if (x === undefined) { x = 0; }
|
|
|
|
if (y === undefined) { y = 0; }
|
|
|
|
if (width === undefined) { width = this.scene.sys.game.config.width; }
|
|
|
|
if (height === undefined) { height = this.scene.sys.game.config.height; }
|
|
|
|
|
|
|
|
this.x = x + (Math.random() * width);
|
|
|
|
this.y = y + (Math.random() * height);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-01 00:50:15 +00:00
|
|
|
/**
|
|
|
|
* Sets the rotation of this Game Object.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-02-01 01:36:52 +00:00
|
|
|
* @method Phaser.GameObjects.Components.Transform#setRotation
|
2018-02-01 00:50:15 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {number} [radians=0] - The rotation of this Game Object, in radians.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-05-22 04:46:26 +00:00
|
|
|
* @return {this} This Game Object instance.
|
2018-02-01 00:50:15 +00:00
|
|
|
*/
|
2017-02-24 01:45:15 +00:00
|
|
|
setRotation: function (radians)
|
|
|
|
{
|
2017-03-09 00:41:21 +00:00
|
|
|
if (radians === undefined) { radians = 0; }
|
|
|
|
|
|
|
|
this.rotation = radians;
|
2017-02-24 01:45:15 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-01 00:50:15 +00:00
|
|
|
/**
|
|
|
|
* Sets the angle of this Game Object.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-02-01 01:36:52 +00:00
|
|
|
* @method Phaser.GameObjects.Components.Transform#setAngle
|
2018-02-01 00:50:15 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {number} [degrees=0] - The rotation of this Game Object, in degrees.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-05-22 04:46:26 +00:00
|
|
|
* @return {this} This Game Object instance.
|
2018-02-01 00:50:15 +00:00
|
|
|
*/
|
2017-07-13 01:05:44 +00:00
|
|
|
setAngle: function (degrees)
|
|
|
|
{
|
|
|
|
if (degrees === undefined) { degrees = 0; }
|
|
|
|
|
|
|
|
this.angle = degrees;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-01 00:50:15 +00:00
|
|
|
/**
|
|
|
|
* Sets the scale of this Game Object.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-02-01 01:36:52 +00:00
|
|
|
* @method Phaser.GameObjects.Components.Transform#setScale
|
2018-02-01 00:50:15 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {number} x - The horizontal scale of this Game Object.
|
2018-03-20 22:28:26 +00:00
|
|
|
* @param {number} [y=x] - The vertical scale of this Game Object. If not set it will use the `x` value.
|
|
|
|
*
|
2018-05-22 04:46:26 +00:00
|
|
|
* @return {this} This Game Object instance.
|
2018-02-01 00:50:15 +00:00
|
|
|
*/
|
2017-02-23 03:10:48 +00:00
|
|
|
setScale: function (x, y)
|
|
|
|
{
|
|
|
|
if (x === undefined) { x = 1; }
|
|
|
|
if (y === undefined) { y = x; }
|
|
|
|
|
2017-03-28 23:43:55 +00:00
|
|
|
this.scaleX = x;
|
|
|
|
this.scaleY = y;
|
2017-02-23 03:10:48 +00:00
|
|
|
|
2017-04-04 22:57:37 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-01 00:50:15 +00:00
|
|
|
/**
|
|
|
|
* Sets the x position of this Game Object.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-02-01 01:36:52 +00:00
|
|
|
* @method Phaser.GameObjects.Components.Transform#setX
|
2018-02-01 00:50:15 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {number} [value=0] - The x position of this Game Object.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-05-22 04:46:26 +00:00
|
|
|
* @return {this} This Game Object instance.
|
2018-02-01 00:50:15 +00:00
|
|
|
*/
|
|
|
|
setX: function (value)
|
2017-09-15 03:04:51 +00:00
|
|
|
{
|
|
|
|
if (value === undefined) { value = 0; }
|
|
|
|
|
2018-02-01 00:50:15 +00:00
|
|
|
this.x = value;
|
2017-09-15 03:04:51 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-01 00:50:15 +00:00
|
|
|
/**
|
|
|
|
* Sets the y position of this Game Object.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-02-01 01:36:52 +00:00
|
|
|
* @method Phaser.GameObjects.Components.Transform#setY
|
2018-02-01 00:50:15 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {number} [value=0] - The y position of this Game Object.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-05-22 04:46:26 +00:00
|
|
|
* @return {this} This Game Object instance.
|
2018-02-01 00:50:15 +00:00
|
|
|
*/
|
|
|
|
setY: function (value)
|
2017-09-15 03:04:51 +00:00
|
|
|
{
|
|
|
|
if (value === undefined) { value = 0; }
|
|
|
|
|
2018-02-01 00:50:15 +00:00
|
|
|
this.y = value;
|
2017-09-15 03:04:51 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-01 00:50:15 +00:00
|
|
|
/**
|
|
|
|
* Sets the z position of this Game Object.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-02-01 01:36:52 +00:00
|
|
|
* @method Phaser.GameObjects.Components.Transform#setZ
|
2018-02-01 00:50:15 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {number} [value=0] - The z position of this Game Object.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-05-22 04:46:26 +00:00
|
|
|
* @return {this} This Game Object instance.
|
2018-02-01 00:50:15 +00:00
|
|
|
*/
|
|
|
|
setZ: function (value)
|
2017-04-04 22:57:37 +00:00
|
|
|
{
|
|
|
|
if (value === undefined) { value = 0; }
|
|
|
|
|
2018-02-01 00:50:15 +00:00
|
|
|
this.z = value;
|
2017-04-04 22:57:37 +00:00
|
|
|
|
2017-02-23 03:10:48 +00:00
|
|
|
return this;
|
2017-12-15 04:08:25 +00:00
|
|
|
},
|
|
|
|
|
2018-02-01 00:50:15 +00:00
|
|
|
/**
|
|
|
|
* Sets the w position of this Game Object.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-02-01 01:36:52 +00:00
|
|
|
* @method Phaser.GameObjects.Components.Transform#setW
|
2018-02-01 00:50:15 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {number} [value=0] - The w position of this Game Object.
|
2018-03-20 22:28:26 +00:00
|
|
|
*
|
2018-05-22 04:46:26 +00:00
|
|
|
* @return {this} This Game Object instance.
|
2018-02-01 00:50:15 +00:00
|
|
|
*/
|
|
|
|
setW: function (value)
|
2017-12-15 04:08:25 +00:00
|
|
|
{
|
2018-02-01 00:50:15 +00:00
|
|
|
if (value === undefined) { value = 0; }
|
2017-12-15 04:08:25 +00:00
|
|
|
|
2018-02-01 00:50:15 +00:00
|
|
|
this.w = value;
|
2017-12-15 04:08:25 +00:00
|
|
|
|
2018-02-01 00:50:15 +00:00
|
|
|
return this;
|
2018-04-05 15:50:37 +00:00
|
|
|
},
|
|
|
|
|
2018-04-06 10:15:15 +00:00
|
|
|
/**
|
|
|
|
* Gets the local transform matrix for this Game Object.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.Transform#getLocalTransformMatrix
|
|
|
|
* @since 3.4.0
|
|
|
|
*
|
2018-04-11 12:17:26 +00:00
|
|
|
* @param {Phaser.GameObjects.Components.TransformMatrix} [tempMatrix] - The matrix to populate with the values from this Game Object.
|
2018-04-06 10:15:15 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Components.TransformMatrix} The populated Transform Matrix.
|
|
|
|
*/
|
2018-04-05 15:50:37 +00:00
|
|
|
getLocalTransformMatrix: function (tempMatrix)
|
|
|
|
{
|
2018-04-11 12:17:26 +00:00
|
|
|
if (tempMatrix === undefined) { tempMatrix = new TransformMatrix(); }
|
|
|
|
|
2018-04-05 15:50:37 +00:00
|
|
|
return tempMatrix.applyITRS(this.x, this.y, this._rotation, this._scaleX, this._scaleY);
|
|
|
|
},
|
|
|
|
|
2018-04-06 10:15:15 +00:00
|
|
|
/**
|
|
|
|
* Gets the world transform matrix for this Game Object, factoring in any parent Containers.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.Transform#getWorldTransformMatrix
|
|
|
|
* @since 3.4.0
|
|
|
|
*
|
2018-04-11 12:17:26 +00:00
|
|
|
* @param {Phaser.GameObjects.Components.TransformMatrix} [tempMatrix] - The matrix to populate with the values from this Game Object.
|
2018-04-06 10:15:15 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Components.TransformMatrix} The populated Transform Matrix.
|
|
|
|
*/
|
2018-04-05 17:11:48 +00:00
|
|
|
getWorldTransformMatrix: function (tempMatrix)
|
2018-04-05 15:50:37 +00:00
|
|
|
{
|
2018-04-11 12:17:26 +00:00
|
|
|
if (tempMatrix === undefined) { tempMatrix = new TransformMatrix(); }
|
|
|
|
|
2018-04-05 15:50:37 +00:00
|
|
|
var parent = this.parentContainer;
|
2018-04-11 12:17:26 +00:00
|
|
|
|
|
|
|
if (!parent)
|
|
|
|
{
|
2018-04-12 13:25:46 +00:00
|
|
|
return this.getLocalTransformMatrix(tempMatrix);
|
2018-04-11 12:17:26 +00:00
|
|
|
}
|
|
|
|
|
2018-04-05 15:50:37 +00:00
|
|
|
var parents = [];
|
2018-04-05 17:11:48 +00:00
|
|
|
|
|
|
|
while (parent)
|
2018-04-05 15:50:37 +00:00
|
|
|
{
|
2018-04-05 17:11:48 +00:00
|
|
|
parents.unshift(parent);
|
2018-04-05 15:50:37 +00:00
|
|
|
parent = parent.parentContainer;
|
|
|
|
}
|
|
|
|
|
2018-04-05 17:11:48 +00:00
|
|
|
tempMatrix.loadIdentity();
|
2018-04-05 15:50:37 +00:00
|
|
|
|
2018-04-05 17:11:48 +00:00
|
|
|
var length = parents.length;
|
|
|
|
|
|
|
|
for (var i = 0; i < length; ++i)
|
|
|
|
{
|
2018-04-06 10:15:15 +00:00
|
|
|
parent = parents[i];
|
|
|
|
|
|
|
|
tempMatrix.translate(parent.x, parent.y);
|
2018-04-12 15:28:05 +00:00
|
|
|
tempMatrix.rotate(parent.rotation);
|
|
|
|
tempMatrix.scale(parent.scaleX, parent.scaleY);
|
2018-04-05 15:50:37 +00:00
|
|
|
}
|
|
|
|
|
2018-04-05 17:11:48 +00:00
|
|
|
tempMatrix.translate(this.x, this.y);
|
|
|
|
tempMatrix.rotate(this._rotation);
|
|
|
|
tempMatrix.scale(this._scaleX, this._scaleY);
|
|
|
|
|
2018-04-05 15:50:37 +00:00
|
|
|
return tempMatrix;
|
2017-02-23 03:10:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Transform;
|