Skip to content

Commit 64a02dd

Browse files
committed
fixed top, bottom, left, right, centerX and centerY to use the updated getBounds and compute their values depending on the parent local coordinate space. I think this is better than using the global getBounds and a lot more convenient because it makes total sense x and centerX for example to be from the same coordinate space and also with this change now these values would be working when the group is a top level display object and also when it is parented by something else. So this loosens the global only getBounds restriction. Also it doesn't really makes sense to align objects with totally different parents but if that is the case separate calculations could be made.
1 parent aad2ab3 commit 64a02dd

1 file changed

Lines changed: 12 additions & 42 deletions

File tree

src/core/Group.js

Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2711,25 +2711,20 @@ Object.defineProperty(Phaser.Group.prototype, "angle", {
27112711
* It is derived by calling `getBounds`, calculating the Groups dimensions based on its
27122712
* visible children.
27132713
*
2714-
* Note that no ancestors are factored into the result, meaning that if this Group is
2715-
* nested within another Group, with heavy transforms on it, the result of this property
2716-
* is likely to be incorrect. It is safe to get and set this property if the Group is a
2717-
* top-level descendant of Phaser.World, or untransformed parents.
2718-
*
27192714
* @name Phaser.Group#centerX
27202715
* @property {number} centerX
27212716
*/
27222717
Object.defineProperty(Phaser.Group.prototype, "centerX", {
27232718

27242719
get: function () {
27252720

2726-
return this.getBounds().centerX;
2721+
return this.getBounds(this.parent).centerX;
27272722

27282723
},
27292724

27302725
set: function (value) {
27312726

2732-
var r = this.getBounds();
2727+
var r = this.getBounds(this.parent);
27332728
var offset = this.x - r.x;
27342729

27352730
this.x = (value + offset) - r.halfWidth;
@@ -2744,25 +2739,20 @@ Object.defineProperty(Phaser.Group.prototype, "centerX", {
27442739
* It is derived by calling `getBounds`, calculating the Groups dimensions based on its
27452740
* visible children.
27462741
*
2747-
* Note that no ancestors are factored into the result, meaning that if this Group is
2748-
* nested within another Group, with heavy transforms on it, the result of this property
2749-
* is likely to be incorrect. It is safe to get and set this property if the Group is a
2750-
* top-level descendant of Phaser.World, or untransformed parents.
2751-
*
27522742
* @name Phaser.Group#centerY
27532743
* @property {number} centerY
27542744
*/
27552745
Object.defineProperty(Phaser.Group.prototype, "centerY", {
27562746

27572747
get: function () {
27582748

2759-
return this.getBounds().centerY;
2749+
return this.getBounds(this.parent).centerY;
27602750

27612751
},
27622752

27632753
set: function (value) {
27642754

2765-
var r = this.getBounds();
2755+
var r = this.getBounds(this.parent);
27662756
var offset = this.y - r.y;
27672757

27682758
this.y = (value + offset) - r.halfHeight;
@@ -2777,25 +2767,20 @@ Object.defineProperty(Phaser.Group.prototype, "centerY", {
27772767
* It is derived by calling `getBounds`, calculating the Groups dimensions based on its
27782768
* visible children.
27792769
*
2780-
* Note that no ancestors are factored into the result, meaning that if this Group is
2781-
* nested within another Group, with heavy transforms on it, the result of this property
2782-
* is likely to be incorrect. It is safe to get and set this property if the Group is a
2783-
* top-level descendant of Phaser.World, or untransformed parents.
2784-
*
27852770
* @name Phaser.Group#left
27862771
* @property {number} left
27872772
*/
27882773
Object.defineProperty(Phaser.Group.prototype, "left", {
27892774

27902775
get: function () {
27912776

2792-
return this.getBounds().left;
2777+
return this.getBounds(this.parent).left;
27932778

27942779
},
27952780

27962781
set: function (value) {
27972782

2798-
var r = this.getBounds();
2783+
var r = this.getBounds(this.parent);
27992784
var offset = this.x - r.x;
28002785

28012786
this.x = value + offset;
@@ -2809,11 +2794,6 @@ Object.defineProperty(Phaser.Group.prototype, "left", {
28092794
*
28102795
* It is derived by calling `getBounds`, calculating the Groups dimensions based on its
28112796
* visible children.
2812-
*
2813-
* Note that no ancestors are factored into the result, meaning that if this Group is
2814-
* nested within another Group, with heavy transforms on it, the result of this property
2815-
* is likely to be incorrect. It is safe to get and set this property if the Group is a
2816-
* top-level descendant of Phaser.World, or untransformed parents.
28172797
*
28182798
* @name Phaser.Group#right
28192799
* @property {number} right
@@ -2822,13 +2802,13 @@ Object.defineProperty(Phaser.Group.prototype, "right", {
28222802

28232803
get: function () {
28242804

2825-
return this.getBounds().right;
2805+
return this.getBounds(this.parent).right;
28262806

28272807
},
28282808

28292809
set: function (value) {
28302810

2831-
var r = this.getBounds();
2811+
var r = this.getBounds(this.parent);
28322812
var offset = this.x - r.x;
28332813

28342814
this.x = (value + offset) - r.width;
@@ -2842,11 +2822,6 @@ Object.defineProperty(Phaser.Group.prototype, "right", {
28422822
*
28432823
* It is derived by calling `getBounds`, calculating the Groups dimensions based on its
28442824
* visible children.
2845-
*
2846-
* Note that no ancestors are factored into the result, meaning that if this Group is
2847-
* nested within another Group, with heavy transforms on it, the result of this property
2848-
* is likely to be incorrect. It is safe to get and set this property if the Group is a
2849-
* top-level descendant of Phaser.World, or untransformed parents.
28502825
*
28512826
* @name Phaser.Group#top
28522827
* @property {number} top
@@ -2855,13 +2830,13 @@ Object.defineProperty(Phaser.Group.prototype, "top", {
28552830

28562831
get: function () {
28572832

2858-
return this.getBounds().top;
2833+
return this.getBounds(this.parent).top;
28592834

28602835
},
28612836

28622837
set: function (value) {
28632838

2864-
var r = this.getBounds();
2839+
var r = this.getBounds(this.parent);
28652840
var offset = this.y - r.y;
28662841

28672842
this.y = (value + offset);
@@ -2876,25 +2851,20 @@ Object.defineProperty(Phaser.Group.prototype, "top", {
28762851
* It is derived by calling `getBounds`, calculating the Groups dimensions based on its
28772852
* visible children.
28782853
*
2879-
* Note that no ancestors are factored into the result, meaning that if this Group is
2880-
* nested within another Group, with heavy transforms on it, the result of this property
2881-
* is likely to be incorrect. It is safe to get and set this property if the Group is a
2882-
* top-level descendant of Phaser.World, or untransformed parents.
2883-
*
28842854
* @name Phaser.Group#bottom
28852855
* @property {number} bottom
28862856
*/
28872857
Object.defineProperty(Phaser.Group.prototype, "bottom", {
28882858

28892859
get: function () {
28902860

2891-
return this.getBounds().bottom;
2861+
return this.getBounds(this.parent).bottom;
28922862

28932863
},
28942864

28952865
set: function (value) {
28962866

2897-
var r = this.getBounds();
2867+
var r = this.getBounds(this.parent);
28982868
var offset = this.y - r.y;
28992869

29002870
this.y = (value + offset) - r.height;

0 commit comments

Comments
 (0)