Skip to content

Commit 0f42b53

Browse files
committed
Physics.Arcade.isPaused allows you to toggle Arcade Physics processing on and off. If true the Body.preUpdate method will be skipped, halting all motion for all bodies. Note that other methods such as collide will still work, so be careful not to call them on paused bodies.
1 parent 6e0f131 commit 0f42b53

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ Version 2.3.0 - "Tarabon" - in dev
6262

6363
### New Features
6464

65+
* `Physics.Arcade.isPaused` allows you to toggle Arcade Physics processing on and off. If `true` the `Body.preUpdate` method will be skipped, halting all motion for all bodies. Note that other methods such as `collide` will still work, so be careful not to call them on paused bodies.
66+
6567
### Updates
6668

6769
* TypeScript definitions fixes and updates (thanks @clark-stevenson @TimvdEijnden)

src/physics/arcade/Body.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ Phaser.Physics.Arcade.Body.prototype = {
369369
*/
370370
preUpdate: function () {
371371

372-
if (!this.enable)
372+
if (!this.enable || this.game.physics.arcade.isPaused)
373373
{
374374
return;
375375
}

src/physics/arcade/World.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ Phaser.Physics.Arcade = function (game) {
6565
*/
6666
this.skipQuadTree = true;
6767

68+
/**
69+
* @property {boolean} isPaused - If `true` the `Body.preUpdate` method will be skipped, halting all motion for all bodies. Note that other methods such as `collide` will still work, so be careful not to call them on paused bodies.
70+
*/
71+
this.isPaused = false;
72+
6873
/**
6974
* @property {Phaser.QuadTree} quadTree - The world QuadTree.
7075
*/
@@ -258,7 +263,7 @@ Phaser.Physics.Arcade.prototype = {
258263
},
259264

260265
/**
261-
* Called automatically by a Physics body, it updates all motion related values on the Body.
266+
* Called automatically by a Physics body, it updates all motion related values on the Body unless `World.isPaused` is `true`.
262267
*
263268
* @method Phaser.Physics.Arcade#updateMotion
264269
* @param {Phaser.Physics.Arcade.Body} The Body object to be updated.

0 commit comments

Comments
 (0)