Added Game core loop stepping support. Super-useful for debugging, and helped me track down the issue with jittery physics collision. Double-win!

This commit is contained in:
photonstorm
2014-01-29 17:10:13 +00:00
parent d51a37211c
commit 651858372c
25 changed files with 1268 additions and 438 deletions
+8 -4
View File
@@ -207,28 +207,32 @@ Phaser.Camera.prototype = {
if (this.deadzone)
{
this._edge = this.target.bounds.x - this.deadzone.x;
// this._edge = this.target.bounds.x - this.deadzone.x;
this._edge = this.target.x - this.deadzone.x;
if (this.view.x > this._edge)
{
this.view.x = this._edge;
}
this._edge = this.target.bounds.right - this.deadzone.x - this.deadzone.width;
// this._edge = this.target.bounds.right - this.deadzone.x - this.deadzone.width;
this._edge = this.target.x + this.target.width - this.deadzone.x - this.deadzone.width;
if (this.view.x < this._edge)
{
this.view.x = this._edge;
}
this._edge = this.target.bounds.y - this.deadzone.y;
// this._edge = this.target.bounds.y - this.deadzone.y;
this._edge = this.target.y - this.deadzone.y;
if (this.view.y > this._edge)
{
this.view.y = this._edge;
}
this._edge = this.target.bounds.bottom - this.deadzone.y - this.deadzone.height;
// this._edge = this.target.bounds.bottom - this.deadzone.y - this.deadzone.height;
this._edge = this.target.y + this.target.height - this.deadzone.y - this.deadzone.height;
if (this.view.y < this._edge)
{
+44 -13
View File
@@ -283,6 +283,10 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant
window.addEventListener('load', this._onBoot, false);
}
this.pendingStep = false;
this.stepping = true;
this.stepCount = 0;
return this;
};
@@ -580,20 +584,32 @@ Phaser.Game.prototype = {
}
else
{
this.plugins.preUpdate();
this.world.preUpdate();
if (!this.pendingStep)
{
if (this.stepping)
{
this.pendingStep = true;
}
this.stage.update();
this.input.update();
this.tweens.update();
this.sound.update();
this.state.update();
this.world.update();
this.particles.update();
this.plugins.update();
this.plugins.preUpdate();
console.log('world preUpdate');
this.world.preUpdate();
this.world.postUpdate();
this.plugins.postUpdate();
this.stage.update();
this.input.update();
this.tweens.update();
this.sound.update();
console.log('state update');
this.state.update();
console.log('world update');
this.world.update();
this.particles.update();
this.plugins.update();
console.log('world postUpdate');
this.world.postUpdate();
this.plugins.postUpdate();
}
if (this.renderType !== Phaser.HEADLESS)
{
@@ -603,11 +619,26 @@ Phaser.Game.prototype = {
this.plugins.postRender();
}
}
},
enableStep: function () {
this.stepping = true;
this.pendingStep = false;
this.stepCount = 0;
},
step: function () {
this.pendingStep = false;
this.stepCount++;
console.log('--------- Game step', this.stepCount);
},
/**
* Nuke the entire game from orbit
*
+8 -9
View File
@@ -156,22 +156,21 @@ Phaser.World.prototype.postUpdate = function () {
*/
Phaser.World.prototype.setBounds = function (x, y, width, height) {
if (width < this.game.width)
{
width = this.game.width;
}
if (width < this.game.width)
{
width = this.game.width;
}
if (height < this.game.height)
{
height = this.game.height;
}
if (height < this.game.height)
{
height = this.game.height;
}
this.bounds.setTo(x, y, width, height);
if (this.camera.bounds)
{
// The Camera can never be smaller than the game size
this.camera.bounds.setTo(x, y, width, height);
}