Skip to content

Commit 181ef7c

Browse files
committed
Added World.frameRate - The frame rate the world will be stepped at. Defaults to 1 / 60, but you can change here. Also see useElapsedTime property.
Added World.useElapsedTime - If true the frameRate value will be ignored and instead p2 will step with the value of Game.Time.physicsElapsed, which is a delta time value. phaserjs#554
1 parent c3f687e commit 181ef7c

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

src/physics/p2/World.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ Phaser.Physics.P2 = function (game, config) {
3333
*/
3434
this.world = new p2.World(config);
3535

36+
/**
37+
* @property {number} frameRate - The frame rate the world will be stepped at. Defaults to 1 / 60, but you can change here. Also see useElapsedTime property.
38+
* @default
39+
*/
40+
this.frameRate = 1 / 60;
41+
42+
/**
43+
* @property {boolean} useElapsedTime - If true the frameRate value will be ignored and instead p2 will step with the value of Game.Time.physicsElapsed, which is a delta time value.
44+
* @default
45+
*/
46+
this.useElapsedTime = false;
47+
3648
/**
3749
* @property {array<Phaser.Physics.P2.Material>} materials - A local array of all created Materials.
3850
* @protected
@@ -592,7 +604,14 @@ Phaser.Physics.P2.prototype = {
592604
*/
593605
update: function () {
594606

595-
this.world.step(1 / 60);
607+
if (this.useElapsedTime)
608+
{
609+
this.world.step(this.game.time.physicsElapsed);
610+
}
611+
else
612+
{
613+
this.world.step(this.frameRate);
614+
}
596615

597616
},
598617

0 commit comments

Comments
 (0)