Skip to content

Commit 96298cf

Browse files
committed
Added new resetFlags method and willStep and delta arguments to preUpdate.
1 parent 9a5a369 commit 96298cf

1 file changed

Lines changed: 33 additions & 12 deletions

File tree

src/physics/arcade/Body.js

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -843,15 +843,14 @@ var Body = new Class({
843843
},
844844

845845
/**
846-
* Prepares the Body for a physics step by resetting all the states and syncing the position
847-
* with the parent Game Object.
846+
* Prepares the Body for a physics step by resetting the `wasTouching`, `touching` and `blocked` states.
848847
*
849-
* This method is only ever called once per game step.
848+
* This method is only called if the physics world is going to run a step this frame.
850849
*
851-
* @method Phaser.Physics.Arcade.Body#preUpdate
852-
* @since 3.17.0
850+
* @method Phaser.Physics.Arcade.Body#resetFlags
851+
* @since 3.18.0
853852
*/
854-
preUpdate: function ()
853+
resetFlags: function ()
855854
{
856855
// Store and reset collision flags
857856
this.wasTouching.none = this.touching.none;
@@ -877,8 +876,26 @@ var Body = new Class({
877876
this.overlapY = 0;
878877

879878
this.embedded = false;
879+
},
880+
881+
/**
882+
* Syncs the position body position with the parent Game Object.
883+
*
884+
* This method is called every game frame, regardless if the world steps or not.
885+
*
886+
* @method Phaser.Physics.Arcade.Body#preUpdate
887+
* @since 3.17.0
888+
*
889+
* @param {boolean} willStep - Will this Body run an update as well?
890+
* @param {number} delta - The delta time, in seconds, elapsed since the last frame.
891+
*/
892+
preUpdate: function (willStep, delta)
893+
{
894+
if (willStep)
895+
{
896+
this.resetFlags();
897+
}
880898

881-
// Updates the transform values
882899
this.updateBounds();
883900

884901
var sprite = this.transform;
@@ -897,18 +914,22 @@ var Body = new Class({
897914
this.prev.x = this.position.x;
898915
this.prev.y = this.position.y;
899916
}
917+
918+
if (willStep)
919+
{
920+
this.update(delta);
921+
}
900922
},
901923

902924
/**
903-
* Performs a single physics step and updates the body velocity, angle, speed and other
904-
* properties.
925+
* Performs a single physics step and updates the body velocity, angle, speed and other properties.
905926
*
906-
* This method can be called multiple times per game step.
927+
* This method can be called multiple times per game frame, depending on the physics step rate.
907928
*
908929
* The results are synced back to the Game Object in `postUpdate`.
909930
*
910931
* @method Phaser.Physics.Arcade.Body#update
911-
* @fires Phaser.Physics.Arcade.World#worldbounds
932+
* @fires Phaser.Physics.Arcade.Events#WORLD_BOUNDS
912933
* @since 3.0.0
913934
*
914935
* @param {number} delta - The delta time, in seconds, elapsed since the last frame.
@@ -947,7 +968,7 @@ var Body = new Class({
947968
/**
948969
* Feeds the Body results back into the parent Game Object.
949970
*
950-
* This method is only ever called once per game step.
971+
* This method is called every game frame, regardless if the world steps or not.
951972
*
952973
* @method Phaser.Physics.Arcade.Body#postUpdate
953974
* @since 3.0.0

0 commit comments

Comments
 (0)