diff --git a/src/gameobjects/components/Transform.js b/src/gameobjects/components/Transform.js index 68991c70fd..fda9781ebd 100644 --- a/src/gameobjects/components/Transform.js +++ b/src/gameobjects/components/Transform.js @@ -520,9 +520,13 @@ var Transform = { return this.getLocalTransformMatrix(tempMatrix); } + var destroyParentMatrix = false; + if (!parentMatrix) { parentMatrix = new TransformMatrix(); + + destroyParentMatrix = true; } tempMatrix.applyITRS(this.x, this.y, this._rotation, this._scaleX, this._scaleY); @@ -536,6 +540,11 @@ var Transform = { parent = parent.parentContainer; } + if (destroyParentMatrix) + { + parentMatrix.destroy(); + } + return tempMatrix; }, @@ -589,6 +598,40 @@ var Transform = { return point; }, + /** + * Gets the world position of this Game Object, factoring in any parent Containers. + * + * @method Phaser.GameObjects.Components.Transform#getWorldPoint + * @since 3.88.0 + * + * @param {Phaser.Math.Vector2} [point] - A Vector2, or point-like object, to store the result in. + * @param {Phaser.GameObjects.Components.TransformMatrix} [tempMatrix] - A temporary matrix to hold the Game Object's values. + * @param {Phaser.GameObjects.Components.TransformMatrix} [parentMatrix] - A temporary matrix to hold parent values. + * + * @return {Phaser.Math.Vector2} The world position of this Game Object. + */ + getWorldPoint: function (point, tempMatrix, parentMatrix) + { + if (point === undefined) { point = new Vector2(); } + + var parent = this.parentContainer; + + if (!parent) + { + point.x = this.x; + point.y = this.y; + + return point; + } + + var worldTransform = this.getWorldTransformMatrix(tempMatrix, parentMatrix); + + point.x = worldTransform.tx; + point.y = worldTransform.ty; + + return point; + }, + /** * Gets the sum total rotation of all of this Game Objects parent Containers. *