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();