Skip to content

Commit 123e61c

Browse files
committed
The Game Object Bounds component has been updated so that it now provides setters for all of the properties, as well as getters. Previously Sprite.left, Sprite.right, Sprite.top and Sprite.bottom were read-only, but they are now available to be set as well, and take into consideration the anchor and scale of the Game Objects.
1 parent c7225cb commit 123e61c

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
394394
* Cache.getJSON will now return an Array if the `key` you provided points to an array instead of an Object (thanks @drhayes #2552 #2551)
395395
* Phaser.Matrix if passed a 0 value would consider it falsy, and replace it with the default by mistake. It now checks if the arguments are `undefined` or `null` and only then sets the defaults (thanks mmcs)
396396
* Group.createMultiple can now accept Arrays for both the `key` and `frame` arguments. This allows you to create multiple sprites using each key and/or frame in the arrays, which is a great and quick way to build diverse Groups. See the JSDocs for complete details and code examples.
397+
* The Game Object Bounds component has been updated so that it now provides setters for all of the properties, as well as getters. Previously `Sprite.left`, `Sprite.right`, `Sprite.top` and `Sprite.bottom` were read-only, but they are now available to be set as well, and take into consideration the anchor and scale of the Game Objects.
397398

398399
### Bug Fixes
399400

src/gameobjects/components/Bounds.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,19 @@ Phaser.Component.Bounds.prototype = {
5454
* This is the same as `x - offsetX`.
5555
*
5656
* @property {number} left
57-
* @readOnly
5857
*/
5958
left: {
6059

6160
get: function () {
6261

6362
return this.x - this.offsetX;
6463

64+
},
65+
66+
set: function (value) {
67+
68+
this.x = value + this.offsetX;
69+
6570
}
6671

6772
},
@@ -71,14 +76,19 @@ Phaser.Component.Bounds.prototype = {
7176
* This is the same as `x + width - offsetX`.
7277
*
7378
* @property {number} right
74-
* @readOnly
7579
*/
7680
right: {
7781

7882
get: function () {
7983

8084
return (this.x + this.width) - this.offsetX;
8185

86+
},
87+
88+
set: function (value) {
89+
90+
this.x = value - (this.width) + this.offsetX;
91+
8292
}
8393

8494
},
@@ -88,14 +98,19 @@ Phaser.Component.Bounds.prototype = {
8898
* This is the same as `y - offsetY`.
8999
*
90100
* @property {number} top
91-
* @readOnly
92101
*/
93102
top: {
94103

95104
get: function () {
96105

97106
return this.y - this.offsetY;
98107

108+
},
109+
110+
set: function (value) {
111+
112+
this.y = value + this.offsetY;
113+
99114
}
100115

101116
},
@@ -105,14 +120,19 @@ Phaser.Component.Bounds.prototype = {
105120
* This is the same as `y + height - offsetY`.
106121
*
107122
* @property {number} bottom
108-
* @readOnly
109123
*/
110124
bottom: {
111125

112126
get: function () {
113127

114128
return (this.y + this.height) - this.offsetY;
115129

130+
},
131+
132+
set: function (value) {
133+
134+
this.y = value - (this.height) + this.offsetY;
135+
116136
}
117137

118138
}

0 commit comments

Comments
 (0)