Skip to content

Commit 6c575ca

Browse files
committed
Arcade.Events.WORLD_STEP is a new event you can listen to. It is emitted by the Arcade Physics World every time the world steps once. It is emitted _after_ the bodies and colliders have been updated. Fix phaserjs#4289
1 parent ef4b3cf commit 6c575ca

4 files changed

Lines changed: 29 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ The following changes took place in the Pointer class:
110110
* `Phaser.Sound.Events#DECODED_ALL` is a new event emitted by the Web Audio Sound Manager when it has finished decoding all of the audio data files passed to the `decodeAudio` method.
111111
* `Phaser.Utils.Objects.Pick` is a new function that will take an object and an array of keys and return a new object containing just the keys provided in the array.
112112
* `Text.align` and `Text.setAlign` can now accept `justify` as a type. It will apply basic justification to multi-line text, adding in extra spaces in order to justify the content. Fix #4291 (thanks @andrewbaranov @Donerkebap13 @dude78GH)
113+
* `Arcade.Events.WORLD_STEP` is a new event you can listen to. It is emitted by the Arcade Physics World every time the world steps once. It is emitted _after_ the bodies and colliders have been updated. Fix #4289 (thanks @fant0m)
113114

114115
### Updates
115116

src/physics/arcade/World.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,7 @@ var World = new Class({
901901
*
902902
* @method Phaser.Physics.Arcade.World#update
903903
* @protected
904+
* @fires Phaser.Physics.Arcade.Events#WORLD_STEP
904905
* @since 3.0.0
905906
*
906907
* @param {number} time - The current timestamp as generated by the Request Animation Frame or SetTimeout.
@@ -961,6 +962,8 @@ var World = new Class({
961962
collider.update();
962963
}
963964
}
965+
966+
this.emit(Events.WORLD_STEP);
964967
}
965968

966969
// Process any additional steps this frame
@@ -976,6 +979,7 @@ var World = new Class({
976979
* Advances the simulation by a time increment.
977980
*
978981
* @method Phaser.Physics.Arcade.World#step
982+
* @fires Phaser.Physics.Arcade.Events#WORLD_STEP
979983
* @since 3.10.0
980984
*
981985
* @param {number} delta - The delta time amount, in seconds, by which to advance the simulation.
@@ -1018,6 +1022,8 @@ var World = new Class({
10181022
}
10191023
}
10201024

1025+
this.emit(Events.WORLD_STEP);
1026+
10211027
this.stepsLastFrame++;
10221028
},
10231029

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2019 Photon Storm Ltd.
4+
* @license {@link https://opensource.org/licenses/MIT|MIT License}
5+
*/
6+
7+
/**
8+
* The Arcade Physics World Step Event.
9+
*
10+
* This event is dispatched by an Arcade Physics World instance whenever a physics step is run.
11+
* It is emitted _after_ the bodies and colliders have been updated.
12+
*
13+
* In high framerate settings this can be multiple times per game frame.
14+
*
15+
* Listen to it from a Scene using: `this.physics.world.on('worldstep', listener)`.
16+
*
17+
* @event Phaser.Physics.Arcade.Events#WORLD_STEP
18+
* @since 3.18.0
19+
*/
20+
module.exports = 'worldstep';

src/physics/arcade/events/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = {
1616
RESUME: require('./RESUME_EVENT'),
1717
TILE_COLLIDE: require('./TILE_COLLIDE_EVENT'),
1818
TILE_OVERLAP: require('./TILE_OVERLAP_EVENT'),
19-
WORLD_BOUNDS: require('./WORLD_BOUNDS_EVENT')
19+
WORLD_BOUNDS: require('./WORLD_BOUNDS_EVENT'),
20+
WORLD_STEP: require('./WORLD_STEP_EVENT')
2021

2122
};

0 commit comments

Comments
 (0)