Skip to content

Commit f66e05b

Browse files
authored
Merge pull request phaserjs#5042 from Minious/master
Fix wrong Container.getBounds with child container
2 parents a03b6e6 + 5fd94d7 commit f66e05b

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/gameobjects/container/Container.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,12 +384,20 @@ var Container = new Class({
384384

385385
output.setTo(this.x, this.y, 0, 0);
386386

387+
if (this.parentContainer) {
388+
var parentMatrix = this.parentContainer.getBoundsTransformMatrix();
389+
var transformedPosition = parentMatrix.transformPoint(this.x, this.y);
390+
output.setTo(transformedPosition.x, transformedPosition.y, 0, 0);
391+
}
392+
387393
if (this.list.length > 0)
388394
{
389395
var children = this.list;
390396
var tempRect = new Rectangle();
391397

392-
for (var i = 0; i < children.length; i++)
398+
var firstChildBounds = children[0].getBounds();
399+
output.setTo(firstChildBounds.x, firstChildBounds.y, firstChildBounds.width, firstChildBounds.height);
400+
for (var i = 1; i < children.length; i++)
393401
{
394402
var entry = children[i];
395403

@@ -468,7 +476,9 @@ var Container = new Class({
468476

469477
if (this.parentContainer)
470478
{
471-
return this.parentContainer.pointToContainer(source, output);
479+
this.parentContainer.pointToContainer(source, output);
480+
} else {
481+
output = new Vector2(source.x, source.y);
472482
}
473483

474484
var tempMatrix = this.tempTransformMatrix;

src/input/InputPlugin.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,6 +2487,9 @@ var InputPlugin = new Class({
24872487
debug.setDepth(gameObject.depth);
24882488
};
24892489

2490+
if(gameObject.parentContainer)
2491+
gameObject.parentContainer.add(debug);
2492+
24902493
updateList.add(debug);
24912494

24922495
input.hitAreaDebug = debug;

0 commit comments

Comments
 (0)