Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Game Object getWorldPoint() #6982

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/gameobjects/components/Transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,40 @@ var Transform = {
return tempMatrix;
},

/**
* Gets the world position of this Game Object, factoring in any parent Containers.
*
* @method Phaser.GameObjects.Components.Transform#getWorldPoint
* @since 4.0.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;
},

/**
* Takes the given `x` and `y` coordinates and converts them into local space for this
* Game Object, taking into account parent and local transforms, and the Display Origin.
Expand Down