@@ -5,7 +5,6 @@ Phaser.Physics.Arcade.Body = function (sprite) {
55
66 this . offset = new Phaser . Point ;
77
8- // the top-left of the Body
98 this . x = sprite . x ;
109 this . y = sprite . y ;
1110
@@ -19,8 +18,6 @@ Phaser.Physics.Arcade.Body = function (sprite) {
1918 this . halfWidth = Math . floor ( sprite . currentFrame . sourceSizeW / 2 ) ;
2019 this . halfHeight = Math . floor ( sprite . currentFrame . sourceSizeH / 2 ) ;
2120
22- this . bounds = new Phaser . Rectangle ( sprite . x , sprite . y , this . width , this . height ) ;
23-
2421 // Scale value cache
2522 this . _sx = sprite . scale . x ;
2623 this . _sy = sprite . scale . y ;
@@ -69,8 +66,6 @@ Phaser.Physics.Arcade.Body.prototype = {
6966 this . height = this . sourceHeight * scaleY ;
7067 this . halfWidth = Math . floor ( this . width / 2 ) ;
7168 this . halfHeight = Math . floor ( this . height / 2 ) ;
72- this . bounds . width = this . width ;
73- this . bounds . height = this . height ;
7469 this . _sx = scaleX ;
7570 this . _sy = scaleY ;
7671 }
@@ -94,19 +89,16 @@ Phaser.Physics.Arcade.Body.prototype = {
9489
9590 this . lastX = this . x ;
9691 this . lastY = this . y ;
97-
98- this . x = this . sprite . x - this . offset . x + ( this . sprite . anchor . x * this . width ) ) ;
99- this . y = this . sprite . y - this . offset . y + ( this . sprite . anchor . y * this . height ) ) ;
10092 this . rotation = this . sprite . angle ;
10193
94+ this . x = ( this . sprite . x - ( this . sprite . anchor . x * this . width ) ) + this . offset . x ;
95+ this . y = ( this . sprite . y - ( this . sprite . anchor . y * this . height ) ) + this . offset . y ;
96+
10297 if ( this . moves )
10398 {
10499 this . game . physics . updateMotion ( this ) ;
105100 }
106101
107- this . bounds . x = this . x ;
108- this . bounds . y = this . y ;
109-
110102 if ( this . collideWorldBounds )
111103 {
112104 this . checkWorldBounds ( ) ;
@@ -120,44 +112,52 @@ Phaser.Physics.Arcade.Body.prototype = {
120112 }
121113
122114 // Adjust the sprite based on all of the above, so the x/y coords will be correct going into the State update
123- // this.sprite.x = this.x - this.offset.x + (this.sprite.anchor.x * this.width);
124- // this.sprite.y = this.y - this.offset.y + (this.sprite.anchor.y * this.height);
125- // this.sprite.x = this.x;
126- // this.sprite.y = this.y;
115+ this . sprite . x = this . x - this . offset . x + ( this . sprite . anchor . x * this . width ) ;
116+ this . sprite . y = this . y - this . offset . y + ( this . sprite . anchor . y * this . height ) ;
117+
118+ if ( this . allowRotation )
119+ {
120+ this . sprite . angle = this . rotation ;
121+ }
122+
123+ } ,
124+
125+ /*
126+ postUpdate: function () {
127+
128+ this.sprite.x = this.x - this.offset.x + (this.sprite.anchor.x * this.width);
129+ this.sprite.y = this.y - this.offset.y + (this.sprite.anchor.y * this.height);
127130
128131 if (this.allowRotation)
129132 {
130- // this.sprite.angle = this.rotation;
133+ this.sprite.angle = this.rotation;
131134 }
132135
133136 },
137+ */
134138
135139 checkWorldBounds : function ( ) {
136140
137- if ( this . bounds . x < this . game . world . bounds . x )
141+ if ( this . x < this . game . world . bounds . x )
138142 {
139143 this . x = this . game . world . bounds . x ;
140- this . velocity . x *= - 1 ;
141- this . velocity . x *= this . bounce . x ;
144+ this . velocity . x *= - this . bounce . x ;
142145 }
143- else if ( this . bounds . right > this . game . world . bounds . right )
146+ else if ( this . right > this . game . world . bounds . right )
144147 {
145148 this . x = this . game . world . bounds . right - this . width ;
146- this . velocity . x *= - 1 ;
147- this . velocity . x *= this . bounce . x ;
149+ this . velocity . x *= - this . bounce . x ;
148150 }
149151
150- if ( this . bounds . y < this . game . world . bounds . y )
152+ if ( this . y < this . game . world . bounds . y )
151153 {
152154 this . y = this . game . world . bounds . y ;
153- this . velocity . y *= - 1 ;
154- this . velocity . y *= this . bounce . y ;
155+ this . velocity . y *= - this . bounce . y ;
155156 }
156- else if ( this . bounds . bottom > this . game . world . bounds . bottom )
157+ else if ( this . bottom > this . game . world . bounds . bottom )
157158 {
158159 this . y = this . game . world . bounds . bottom - this . height ;
159- this . velocity . y *= - 1 ;
160- this . velocity . y *= this . bounce . y ;
160+ this . velocity . y *= - this . bounce . y ;
161161 }
162162
163163 } ,
@@ -173,8 +173,6 @@ Phaser.Physics.Arcade.Body.prototype = {
173173 this . height = this . sourceHeight * this . _sy ;
174174 this . halfWidth = Math . floor ( this . width / 2 ) ;
175175 this . halfHeight = Math . floor ( this . height / 2 ) ;
176- this . bounds . width = this . width ;
177- this . bounds . height = this . height ;
178176 this . offset . setTo ( offsetX , offsetY ) ;
179177
180178 } ,
@@ -195,4 +193,60 @@ Phaser.Physics.Arcade.Body.prototype = {
195193 return this . y - this . lastY ;
196194 }
197195
198- } ;
196+ } ;
197+
198+ Object . defineProperty ( Phaser . Physics . Arcade . Body . prototype , "bottom" , {
199+
200+ /**
201+ * The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
202+ * @method bottom
203+ * @return {Number }
204+ **/
205+ get : function ( ) {
206+ return this . y + this . height ;
207+ } ,
208+
209+ /**
210+ * The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
211+ * @method bottom
212+ * @param {Number } value
213+ **/
214+ set : function ( value ) {
215+ if ( value <= this . y ) {
216+ this . height = 0 ;
217+ } else {
218+ this . height = ( this . y - value ) ;
219+ }
220+ } ,
221+ enumerable : true ,
222+ configurable : true
223+ } ) ;
224+
225+ Object . defineProperty ( Phaser . Physics . Arcade . Body . prototype , "right" , {
226+
227+ /**
228+ * The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
229+ * However it does affect the width property.
230+ * @method right
231+ * @return {Number }
232+ **/
233+ get : function ( ) {
234+ return this . x + this . width ;
235+ } ,
236+
237+ /**
238+ * The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
239+ * However it does affect the width property.
240+ * @method right
241+ * @param {Number } value
242+ **/
243+ set : function ( value ) {
244+ if ( value <= this . x ) {
245+ this . width = 0 ;
246+ } else {
247+ this . width = this . x + value ;
248+ }
249+ } ,
250+ enumerable : true ,
251+ configurable : true
252+ } ) ;
0 commit comments