Added getWorldTransformMatrix to Container and added support to parent container transform to GetBounds component.

This commit is contained in:
Felipe Alfonso 2018-04-11 12:55:32 -03:00
parent 091d947eae
commit 23cd9868b4
2 changed files with 76 additions and 17 deletions

View file

@ -20,6 +20,7 @@ var GetBounds = {
/**
* Gets the center coordinate of this Game Object, regardless of origin.
* The returned point is calculated in local space and does not factor in any parent containers
*
* @method Phaser.GameObjects.Components.GetBounds#getCenter
* @since 3.0.0
@ -42,6 +43,7 @@ var GetBounds = {
/**
* Gets the top-left corner coordinate of this Game Object, regardless of origin.
* The returned point is calculated in local space and does not factor in any parent containers
*
* @method Phaser.GameObjects.Components.GetBounds#getTopLeft
* @since 3.0.0
@ -69,6 +71,7 @@ var GetBounds = {
/**
* Gets the top-right corner coordinate of this Game Object, regardless of origin.
* The returned point is calculated in local space and does not factor in any parent containers
*
* @method Phaser.GameObjects.Components.GetBounds#getTopRight
* @since 3.0.0
@ -96,6 +99,7 @@ var GetBounds = {
/**
* Gets the bottom-left corner coordinate of this Game Object, regardless of origin.
* The returned point is calculated in local space and does not factor in any parent containers
*
* @method Phaser.GameObjects.Components.GetBounds#getBottomLeft
* @since 3.0.0
@ -123,6 +127,7 @@ var GetBounds = {
/**
* Gets the bottom-right corner coordinate of this Game Object, regardless of origin.
* The returned point is calculated in local space and does not factor in any parent containers
*
* @method Phaser.GameObjects.Components.GetBounds#getBottomRight
* @since 3.0.0
@ -167,36 +172,66 @@ var GetBounds = {
// We can use the output object to temporarily store the x/y coords in:
var TLx, TLy, TRx, TRy, BLx, BLy, BRx, BRy;
// Instead of doing a check if parent container is
// defined per corner we only do it once.
if (this.parentContainer)
{
var parentMatrix = this.parentContainer.getWorldTransformMatrix();
this.getTopLeft(output);
parentMatrix.transformPoint(output.x, output.y, output);
TLx = output.x;
TLy = output.y;
this.getTopRight(output);
parentMatrix.transformPoint(output.x, output.y, output);
TRx = output.x;
TRy = output.y;
this.getBottomLeft(output);
parentMatrix.transformPoint(output.x, output.y, output);
BLx = output.x;
BLy = output.y;
this.getBottomRight(output);
parentMatrix.transformPoint(output.x, output.y, output);
BRx = output.x;
BRy = output.y;
}
else
{
this.getTopLeft(output);
var TLx = output.x;
var TLy = output.y;
TLx = output.x;
TLy = output.y;
this.getTopRight(output);
var TRx = output.x;
var TRy = output.y;
TRx = output.x;
TRy = output.y;
this.getBottomLeft(output);
var BLx = output.x;
var BLy = output.y;
BLx = output.x;
BLy = output.y;
this.getBottomRight(output);
var BRx = output.x;
var BRy = output.y;
BRx = output.x;
BRy = output.y;
}
output.x = Math.min(TLx, TRx, BLx, BRx);
output.y = Math.min(TLy, TRy, BLy, BRy);
output.width = Math.max(TLx, TRx, BLx, BRx) - output.x;
output.height = Math.max(TLy, TRy, BLy, BRy) - output.y;
if (this.parentContainer)
{
// Clearly something needs to happen here :)
}
return output;
}

View file

@ -329,6 +329,30 @@ var Container = new Class({
return output;
},
/**
* Returns the world transform matrix.
* The returned matrix is a temporal and shouldn't be stored.
*
* @method Phaser.GameObjects.Container#getWorldTransformMatrix
* @since 3.4.0
*
* @return {Phaser.GameObjects.Components.TransformMatrix} The world transform matrix.
*/
getWorldTransformMatrix: function ()
{
var tempMatrix = this.tempTransformMatrix;
tempMatrix.applyITRS(this.x, this.y, this.rotation, this.scaleX, this.scaleY);
if (this.parentContainer)
{
var parentMatrix = this.parentContainer.getTransformMatrix();
tempMatrix.multiply(parentMatrix);
}
return tempMatrix;
},
/**
* Adds the given Game Object, or array of Game Objects, to this Container.
*