From 336de314a16b92f7d56f61b75e9e7f978609cc01 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Thu, 12 Sep 2013 16:18:44 +0100 Subject: [PATCH] Fixed an issue where the Tile.physicsElapsed would go insane if the game has been paused for a long time. --- src/core/Group.js | 6 +++--- src/tilemap/Tilemap.js | 26 ++++++++++++-------------- src/time/Time.js | 41 +++++++++++++++-------------------------- 3 files changed, 30 insertions(+), 43 deletions(-) diff --git a/src/core/Group.js b/src/core/Group.js index 86681283..b1826041 100644 --- a/src/core/Group.js +++ b/src/core/Group.js @@ -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) { diff --git a/src/tilemap/Tilemap.js b/src/tilemap/Tilemap.js index 070c32dc..93deb185 100644 --- a/src/tilemap/Tilemap.js +++ b/src/tilemap/Tilemap.js @@ -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); diff --git a/src/time/Time.js b/src/time/Time.js index 4be752a0..b141e24f 100644 --- a/src/time/Time.js +++ b/src/time/Time.js @@ -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; },