Fixed issue with the camera being slightly out of sync with 'fixedToCamera' sprites. Also fixed 'jitter' issue with camera targets.

This commit is contained in:
photonstorm
2014-01-31 03:32:12 +00:00
parent 6e4e99f436
commit 68b7d22e0d
7 changed files with 121 additions and 80 deletions
+17 -9
View File
@@ -39,7 +39,7 @@ Phaser.Camera = function (game, id, x, y, width, height) {
* Camera view.
* The view into the world we wish to render (by default the game dimensions).
* The x/y values are in world coordinates, not screen coordinates, the width/height is how many pixels to render.
* Objects outside of this view are not rendered (unless set to ignore the Camera, i.e. UI?).
* Objects outside of this view are not rendered if set to camera cull.
* @property {Phaser.Rectangle} view
*/
this.view = new Phaser.Rectangle(x, y, width, height);
@@ -86,6 +86,9 @@ Phaser.Camera = function (game, id, x, y, width, height) {
*/
this._edge = 0;
/**
* @property {PIXI.DisplayObject} displayObject - The display object to which all game objects are added. Set by World.boot
*/
this.displayObject = null;
};
@@ -203,11 +206,15 @@ Phaser.Camera.prototype = {
},
/**
* Internal method
* @method Phaser.Camera#updateTarget
* @private
*/
updateTarget: function () {
if (this.deadzone)
{
// this._edge = this.target.bounds.x - this.deadzone.x;
this._edge = this.target.x - this.deadzone.x;
if (this.view.x > this._edge)
@@ -215,7 +222,6 @@ Phaser.Camera.prototype = {
this.view.x = this._edge;
}
// 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)
@@ -223,7 +229,6 @@ Phaser.Camera.prototype = {
this.view.x = this._edge;
}
// this._edge = this.target.bounds.y - this.deadzone.y;
this._edge = this.target.y - this.deadzone.y;
if (this.view.y > this._edge)
@@ -231,7 +236,6 @@ Phaser.Camera.prototype = {
this.view.y = this._edge;
}
// 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)
@@ -246,6 +250,10 @@ Phaser.Camera.prototype = {
},
/**
* Update the Camera bounds to match the game world.
* @method Phaser.Camera#setBoundsToWorld
*/
setBoundsToWorld: function () {
this.bounds.setTo(this.game.world.bounds.x, this.game.world.bounds.y, this.game.world.bounds.width, this.game.world.bounds.height);
@@ -268,10 +276,10 @@ Phaser.Camera.prototype = {
this.view.x = this.bounds.x;
}
if (this.view.x > this.bounds.right - this.width)
if (this.view.right > this.bounds.right)
{
this.atLimit.x = true;
this.view.x = (this.bounds.right - this.width) + 1;
this.view.x = this.bounds.right - this.width;
}
if (this.view.y < this.bounds.top)
@@ -280,10 +288,10 @@ Phaser.Camera.prototype = {
this.view.y = this.bounds.top;
}
if (this.view.y > this.bounds.bottom - this.height)
if (this.view.bottom > this.bounds.bottom)
{
this.atLimit.y = true;
this.view.y = (this.bounds.bottom - this.height) + 1;
this.view.y = this.bounds.bottom - this.height;
}
this.view.floor();
+2 -2
View File
@@ -592,7 +592,7 @@ Phaser.Game.prototype = {
}
this.plugins.preUpdate();
console.log('world preUpdate');
// console.log('world preUpdate');
this.world.preUpdate();
this.stage.update();
@@ -606,7 +606,7 @@ Phaser.Game.prototype = {
this.particles.update();
this.plugins.update();
console.log('world postUpdate');
// console.log('world postUpdate');
this.world.postUpdate();
this.plugins.postUpdate();
}
+48 -19
View File
@@ -61,7 +61,8 @@ Phaser.World.prototype.boot = function () {
}
/**
* This is called automatically every frame, and is where main logic happens.
* This is called automatically after the plugins preUpdate and before the State.update.
* Most objects have preUpdate methods and it's where initial movement, drawing and calculations are done.
*
* @method Phaser.World#update
*/
@@ -90,7 +91,8 @@ Phaser.World.prototype.preUpdate = function () {
}
/**
* This is called automatically every frame, and is where main logic happens.
* This is called automatically after the State.update, but before particles or plugins update.
* Most objects won't have an update method set unless explicitly given one.
*
* @method Phaser.World#update
*/
@@ -121,31 +123,58 @@ Phaser.World.prototype.update = function () {
}
/**
* This is called automatically every frame, and is where main logic happens.
* This is called automatically before the renderer runs and after the plugins have updated.
* In postUpdate this is where all the final physics calculatations and object positioning happens.
* The objects are processed in the order of the display list.
* The only exception to this is if the camera is following an object, in which case that is updated first.
*
* @method Phaser.World#postUpdate
*/
Phaser.World.prototype.postUpdate = function () {
this.camera.update();
if (this.game.stage._stage.first._iNext)
if (this.camera.target && this.camera.target['postUpdate'])
{
var currentNode = this.game.stage._stage.first._iNext;
do
this.camera.target.postUpdate();
this.camera.update();
if (this.game.stage._stage.first._iNext)
{
if (currentNode['postUpdate'])
{
currentNode.postUpdate();
}
var currentNode = this.game.stage._stage.first._iNext;
currentNode = currentNode._iNext;
do
{
if (currentNode['postUpdate'] && currentNode !== this.camera.target)
{
currentNode.postUpdate();
}
currentNode = currentNode._iNext;
}
while (currentNode != this.game.stage._stage.last._iNext)
}
}
else
{
this.camera.update();
if (this.game.stage._stage.first._iNext)
{
var currentNode = this.game.stage._stage.first._iNext;
do
{
if (currentNode['postUpdate'])
{
currentNode.postUpdate();
}
currentNode = currentNode._iNext;
}
while (currentNode != this.game.stage._stage.last._iNext)
}
while (currentNode != this.game.stage._stage.last._iNext)
}
this.camera.update();
}
/**
@@ -154,8 +183,8 @@ Phaser.World.prototype.postUpdate = function () {
* @method Phaser.World#setBounds
* @param {number} x - Top left most corner of the world.
* @param {number} y - Top left most corner of the world.
* @param {number} width - New width of the world.
* @param {number} height - New height of the world.
* @param {number} width - New width of the world. Can never be smaller than the Game.width.
* @param {number} height - New height of the world. Can never be smaller than the Game.height.
*/
Phaser.World.prototype.setBounds = function (x, y, width, height) {