Skip to content

Commit f16a16b

Browse files
authored
Merge pull request phaserjs#4729 from Gamefroot/arcade-physics-fps-fixes
Arcade physics fps fixes
2 parents ce29cb2 + 95d413d commit f16a16b

4 files changed

Lines changed: 22 additions & 26 deletions

File tree

src/physics/arcade/Body.js

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,15 @@ var Body = new Class({
158158
*/
159159
this.prev = new Vector2(gameObject.x, gameObject.y);
160160

161+
/**
162+
* The position of this Body during the previous frame.
163+
*
164+
* @name Phaser.Physics.Arcade.Body#prevFrame
165+
* @type {Phaser.Math.Vector2}
166+
* @author Benjamin D. Richards <benjamindrichards@gmail.com>
167+
*/
168+
this.prevFrame = new Vector2(gameObject.x, gameObject.y);
169+
161170
/**
162171
* Whether this Body's `rotation` is affected by its angular acceleration and angular velocity.
163172
*
@@ -695,17 +704,6 @@ var Body = new Class({
695704
*/
696705
this.physicsType = CONST.DYNAMIC_BODY;
697706

698-
/**
699-
* Whether the Body's position needs updating from its Game Object.
700-
*
701-
* @name Phaser.Physics.Arcade.Body#_reset
702-
* @type {boolean}
703-
* @private
704-
* @default true
705-
* @since 3.0.0
706-
*/
707-
this._reset = true;
708-
709707
/**
710708
* Cached horizontal scale of the Body's Game Object.
711709
*
@@ -908,10 +906,12 @@ var Body = new Class({
908906

909907
this.preRotation = this.rotation;
910908

911-
if (this._reset)
909+
if (this.moves)
912910
{
913911
this.prev.x = this.position.x;
914912
this.prev.y = this.position.y;
913+
this.prevFrame.x = this.position.x;
914+
this.prevFrame.y = this.position.y;
915915
}
916916

917917
if (willStep)
@@ -935,6 +935,9 @@ var Body = new Class({
935935
*/
936936
update: function (delta)
937937
{
938+
this.prev.x = this.position.x;
939+
this.prev.y = this.position.y;
940+
938941
if (this.moves)
939942
{
940943
this.world.updateMotion(this, delta);
@@ -974,8 +977,8 @@ var Body = new Class({
974977
*/
975978
postUpdate: function ()
976979
{
977-
var dx = this.position.x - this.prev.x;
978-
var dy = this.position.y - this.prev.y;
980+
var dx = this.position.x - this.prevFrame.x;
981+
var dy = this.position.y - this.prevFrame.y;
979982

980983
if (this.moves)
981984
{
@@ -1008,8 +1011,6 @@ var Body = new Class({
10081011

10091012
this.gameObject.x += dx;
10101013
this.gameObject.y += dy;
1011-
1012-
this._reset = true;
10131014
}
10141015

10151016
if (dx < 0)
@@ -1030,16 +1031,10 @@ var Body = new Class({
10301031
this.facing = CONST.FACING_DOWN;
10311032
}
10321033

1033-
this._dx = dx;
1034-
this._dy = dy;
1035-
10361034
if (this.allowRotation)
10371035
{
10381036
this.gameObject.angle += this.deltaZ();
10391037
}
1040-
1041-
this.prev.x = this.position.x;
1042-
this.prev.y = this.position.y;
10431038
},
10441039

10451040
/**

src/physics/arcade/World.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,7 @@ var World = new Class({
10461046
// We don't need to postUpdate if there wasn't a step this frame
10471047
if (this.stepsLastFrame)
10481048
{
1049+
this.stepsLastFrame = 0;
10491050
for (i = 0; i < len; i++)
10501051
{
10511052
body = bodies[i];

src/physics/arcade/tilemap/TileCheckX.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var TileCheckX = function (body, tile, tileLeft, tileRight, tileBias, isLayer)
3939
collideRight = true;
4040
}
4141

42-
if (body.deltaX() < 0 && !body.blocked.left && collideRight && body.checkCollision.left)
42+
if (body.deltaX() < 0 && collideRight && body.checkCollision.left)
4343
{
4444
// Body is moving LEFT
4545
if (faceRight && body.x < tileRight)
@@ -52,7 +52,7 @@ var TileCheckX = function (body, tile, tileLeft, tileRight, tileBias, isLayer)
5252
}
5353
}
5454
}
55-
else if (body.deltaX() > 0 && !body.blocked.right && collideLeft && body.checkCollision.right)
55+
else if (body.deltaX() > 0 && collideLeft && body.checkCollision.right)
5656
{
5757
// Body is moving RIGHT
5858
if (faceLeft && body.right > tileLeft)

src/physics/arcade/tilemap/TileCheckY.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var TileCheckY = function (body, tile, tileTop, tileBottom, tileBias, isLayer)
3939
collideDown = true;
4040
}
4141

42-
if (body.deltaY() < 0 && !body.blocked.up && collideDown && body.checkCollision.up)
42+
if (body.deltaY() < 0 && collideDown && body.checkCollision.up)
4343
{
4444
// Body is moving UP
4545
if (faceBottom && body.y < tileBottom)
@@ -52,7 +52,7 @@ var TileCheckY = function (body, tile, tileTop, tileBottom, tileBias, isLayer)
5252
}
5353
}
5454
}
55-
else if (body.deltaY() > 0 && !body.blocked.down && collideUp && body.checkCollision.down)
55+
else if (body.deltaY() > 0 && collideUp && body.checkCollision.down)
5656
{
5757
// Body is moving DOWN
5858
if (faceTop && body.bottom > tileTop)

0 commit comments

Comments
 (0)