PIXI.DisplayObject.worldPosition contains the position of the DisplayObject (and therefore any object that inherits from it, such as Phaser.Sprite) taking into account all transforms in the display list. It is updated at the end of DisplayObject.updateTransform. DisplayObject.position reflects only the position applied to the object directly, whereas worldPosition includes the positions that may have been applied to its ancestors.

PIXI.DisplayObject.worldScale contains the scale of the DisplayObject (and therefore any object that inherits from it, such as Phaser.Sprite) taking into account all transforms in the display list. It is updated at the end of `DisplayObject.updateTransform`. DisplayObject.scale reflects only the scale applied to the object directly, whereas worldScale includes any scales that may have been applied to its ancestors.

PIXI.DisplayObject.worldRotation contains the rotation of the DisplayObject (and therefore any object that inherits from it, such as Phaser.Sprite) taking into account all transforms in the display list. It is updated at the end of `DisplayObject.updateTransform`. DisplayObject.rotation reflects only the rotation applied to the object directly, whereas worldRotation includes any rotations that may have been applied to its ancestors.
This commit is contained in:
photonstorm 2015-05-03 13:36:44 +01:00
parent f0ac93ea62
commit a686f6e212

View file

@ -132,6 +132,36 @@ PIXI.DisplayObject = function()
*/ */
this.worldTransform = new PIXI.Matrix(); this.worldTransform = new PIXI.Matrix();
/**
* The position of the Display Object based on the world transform.
* This value is updated at the end of updateTransform and takes all parent transforms into account.
*
* @property worldPosition
* @type Point
* @readOnly
*/
this.worldPosition = new PIXI.Point(0, 0);
/**
* The scale of the Display Object based on the world transform.
* This value is updated at the end of updateTransform and takes all parent transforms into account.
*
* @property worldScale
* @type Point
* @readOnly
*/
this.worldScale = new PIXI.Point(1, 1);
/**
* The rotation of the Display Object, in radians, based on the world transform.
* This value is updated at the end of updateTransform and takes all parent transforms into account.
*
* @property worldRotation
* @type Number
* @readOnly
*/
this.worldRotation = 0;
/** /**
* cached sin rotation and cos rotation * cached sin rotation and cos rotation
* *
@ -454,6 +484,10 @@ PIXI.DisplayObject.prototype.updateTransform = function(parent)
// multiply the alphas.. // multiply the alphas..
this.worldAlpha = this.alpha * p.worldAlpha; this.worldAlpha = this.alpha * p.worldAlpha;
this.worldPosition.set(wt.tx, wt.ty);
this.worldScale.set(Math.sqrt(wt.a * wt.a + wt.b * wt.b), Math.sqrt(wt.c * wt.c + wt.d * wt.d));
this.worldRotation = Math.atan2(-wt.c, wt.d);
// Custom callback? // Custom callback?
if (this.transformCallback) if (this.transformCallback)
{ {