Skip to content

Commit 7c55e65

Browse files
committed
Arcade Physics Body deltaX and deltaY methods will now return the previous steps delta values, rather than zero. Fix phaserjs#3987
1 parent 3d989e1 commit 7c55e65

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ Setting the `resolution` property in the Game Config to a value other than 1 wou
252252
* Calling Arcade Physics `collide` during an `update` method wouldn't inject the results back into the Body parent, causing the bodies to carry on moving. Using Colliders worked, but manually checking did not. Now, both methods work. Fix #3777 (thanks @samme)
253253
* The `setTintFill` method would ignore the `alpha` value of the Game Object in the shader. The alpha value is now blended with the tint fill, allowing you to properly alpha out tint-filled Game Objects. Fix #3992 (thanks @trl-bsd)
254254
* Arcade Physics World `collideSpriteVsTilemapLayer` now syncs the collision results back to the body, allowing you to call `collide` from within an update loop once again. Fix #3999 (thanks @nkholski @mikewesthad)
255+
* Arcade Physics Body `deltaX` and `deltaY` methods will now return the previous steps delta values, rather than zero. Fix #3987 (thanks @HaoboZ)
255256

256257
### Examples, Documentation and TypeScript
257258

src/physics/arcade/Body.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -920,8 +920,8 @@ var Body = new Class({
920920
}
921921
}
922922

923-
this._dx = this.deltaX();
924-
this._dy = this.deltaY();
923+
this._dx = this.position.x - this.prev.x;
924+
this._dy = this.position.y - this.prev.y;
925925
},
926926

927927
/**
@@ -934,8 +934,8 @@ var Body = new Class({
934934
*/
935935
postUpdate: function ()
936936
{
937-
this._dx = this.deltaX();
938-
this._dy = this.deltaY();
937+
this._dx = this.position.x - this.prev.x;
938+
this._dy = this.position.y - this.prev.y;
939939

940940
if (this.moves)
941941
{
@@ -1327,7 +1327,7 @@ var Body = new Class({
13271327
*/
13281328
deltaX: function ()
13291329
{
1330-
return this.position.x - this.prev.x;
1330+
return this._dx;
13311331
},
13321332

13331333
/**
@@ -1341,7 +1341,7 @@ var Body = new Class({
13411341
*/
13421342
deltaY: function ()
13431343
{
1344-
return this.position.y - this.prev.y;
1344+
return this._dy;
13451345
},
13461346

13471347
/**

src/physics/arcade/World.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,10 @@ var World = new Class({
16651665
this.emit('collide', body1.gameObject, body2.gameObject, body1, body2);
16661666
}
16671667

1668+
// sync changes back to the bodies
1669+
body1.postUpdate();
1670+
body2.postUpdate();
1671+
16681672
return true;
16691673
},
16701674

0 commit comments

Comments
 (0)