Fixed an issue where the Tile.physicsElapsed would go insane if the game has been paused for a long time.

This commit is contained in:
Richard Davey 2013-09-12 16:18:44 +01:00
parent 92e86494e3
commit 336de314a1
3 changed files with 30 additions and 43 deletions

View file

@ -449,7 +449,7 @@ Phaser.Group.prototype = {
forEach: function (callback, callbackContext, checkExists) {
checkExists = checkExists || false;
if (typeof checkExists == 'undefined') { checkExists = false; }
if (this._container.first._iNext)
{
@ -470,7 +470,7 @@ Phaser.Group.prototype = {
},
forEachAlive: function () {
forEachAlive: function (callback, callbackContext) {
if (this._container.first._iNext)
{
@ -491,7 +491,7 @@ Phaser.Group.prototype = {
},
forEachDead: function () {
forEachDead: function (callback, callbackContext) {
if (this._container.first._iNext)
{

View file

@ -217,7 +217,6 @@ Phaser.Tilemap.prototype.setCollisionRange = function (start, end, left, right,
for (var i = start; i < end; i++)
{
//setCollision: function (left, right, up, down, reset, separateX, separateY) {
this.tiles[i].setCollision(left, right, up, down, resetCollisions, separateX, separateY);
}
@ -231,16 +230,15 @@ Phaser.Tilemap.prototype.setCollisionRange = function (start, end, left, right,
* @param separateX {bool} Enable seprate at x-axis.
* @param separateY {bool} Enable seprate at y-axis.
*/
Phaser.Tilemap.prototype.setCollisionByIndex = function (values, collision, resetCollisions, separateX, separateY) {
Phaser.Tilemap.prototype.setCollisionByIndex = function (values, left, right, up, down, resetCollisions, separateX, separateY) {
if (typeof collision === "undefined") { collision = Phaser.Types.ANY; }
if (typeof resetCollisions === "undefined") { resetCollisions = false; }
if (typeof separateX === "undefined") { separateX = true; }
if (typeof separateY === "undefined") { separateY = true; }
for (var i = 0; i < values.length; i++)
{
this.tiles[values[i]].setCollision(collision, resetCollisions, separateX, separateY);
this.tiles[values[i]].setCollision(left, right, up, down, resetCollisions, separateX, separateY);
}
};
@ -328,25 +326,20 @@ Phaser.Tilemap.prototype.getTileOverlaps = function (object) {
*/
Phaser.Tilemap.prototype.collide = function (objectOrGroup, callback, context) {
if (typeof objectOrGroup === "undefined") { objectOrGroup = null; }
if (typeof callback === "undefined") { callback = null; }
if (typeof context === "undefined") { context = null; }
objectOrGroup = objectOrGroup || this.game.world.group;
callback = callback || null;
context = context || null;
if (callback !== null && context !== null)
if (callback && context)
{
this.collisionCallback = callback;
this.collisionCallbackContext = context;
}
if (objectOrGroup == null)
{
objectOrGroup = this.game.world.group;
}
// Group?
if (objectOrGroup instanceof Phaser.Group)
{
// objectOrGroup.forEachAlive(this, this.collideGameObject, true);
objectOrGroup.forEachAlive(this.collideGameObject, this);
}
else
{
@ -362,6 +355,11 @@ Phaser.Tilemap.prototype.collide = function (objectOrGroup, callback, context) {
*/
Phaser.Tilemap.prototype.collideGameObject = function (object) {
if (object instanceof Phaser.Group || object instanceof Phaser.Tilemap)
{
return false;
}
if (object.exists && object.body.allowCollision.none == false)
{
this._tempCollisionData = this.collisionLayer.getTileOverlaps(object);

View file

@ -186,20 +186,27 @@ Phaser.Time.prototype = {
update: function (time) {
this.now = time;
this.timeToCall = Math.max(0, 16 - (time - this.lastTime));
if (this._justResumed)
{
this.time = this.now;
this._justResumed = false;
}
this.timeToCall = this.game.math.max(0, 16 - (time - this.lastTime));
this.elapsed = this.now - this.time;
this.msMin = Math.min(this.msMin, this.elapsed);
this.msMax = Math.max(this.msMax, this.elapsed);
this.msMin = this.game.math.min(this.msMin, this.elapsed);
this.msMax = this.game.math.max(this.msMax, this.elapsed);
this.frames++;
if (this.now > this._timeLastSecond + 1000)
{
this.fps = Math.round((this.frames * 1000) / (this.now - this._timeLastSecond));
this.fpsMin = Math.min(this.fpsMin, this.fps);
this.fpsMax = Math.max(this.fpsMax, this.fps);
this.fpsMin = this.game.math.min(this.fpsMin, this.fps);
this.fpsMax = this.game.math.max(this.fpsMax, this.fps);
this._timeLastSecond = this.now;
this.frames = 0;
}
@ -214,18 +221,6 @@ Phaser.Time.prototype = {
this.pausedTime = this.now - this._pauseStarted;
}
if (this._justResumed)
{
console.log('Time just resumed');
console.log('now', this.now);
console.log('timeToCall', this.timeToCall);
console.log('elapsed', this.elapsed);
console.log('lastTime', this.lastTime);
console.log('physicsElapsed', this.physicsElapsed);
this._justResumed = false;
}
},
/**
@ -234,13 +229,9 @@ Phaser.Time.prototype = {
* @private
*/
gamePaused: function () {
this._pauseStarted = this.now;
console.log('Time paused');
console.log('now', this.now);
console.log('timeToCall', this.timeToCall);
console.log('elapsed', this.elapsed);
console.log('lastTime', this.lastTime);
console.log('physicsElapsed', this.physicsElapsed);
},
/**
@ -251,10 +242,8 @@ Phaser.Time.prototype = {
gameResumed: function () {
// Level out the elapsed timer to avoid spikes
this.elapsed = 0;
this.physicsElapsed = 0;
this.time = Date.now();
this.pauseDuration = this.pausedTime;
this._justResumed = true;
},