Skip to content

Commit 92dbabb

Browse files
committed
Camera.updateTarget has had a make-over and now is a lot smoother under certain conditions (thanks @tjkopena, fix phaserjs#966)
1 parent 336cd8b commit 92dbabb

2 files changed

Lines changed: 14 additions & 18 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ Version 2.0.6 - "Jornhill" - -in development-
122122
* Group.removeBetween has a new optional boolean parameter: `silent`. If set to `true` the children will not dispatch their `onRemovedFromGroup` events.
123123
* Group.removeAll has a new optional boolean parameter: `silent`. If set to `true` the children will not dispatch their `onRemovedFromGroup` events.
124124
* Internal child movements in Group (such as bringToTop) now uses the new `silent` parameter to avoid the child emitting incorrect Group addition and deletion events.
125+
* Camera.updateTarget has had a make-over and now is a lot smoother under certain conditions (thanks @tjkopena, fix #966)
125126

126127

127128
### Bug Fixes

src/core/Camera.js

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Phaser.Camera = function (game, id, x, y, width, height) {
5858
this.bounds = new Phaser.Rectangle(x, y, width, height);
5959

6060
/**
61-
* @property {Phaser.Rectangle} deadzone - Moving inside this Rectangle will not cause camera moving.
61+
* @property {Phaser.Rectangle} deadzone - Moving inside this Rectangle will not cause the camera to move.
6262
*/
6363
this.deadzone = null;
6464

@@ -231,37 +231,32 @@ Phaser.Camera.prototype = {
231231

232232
if (this.deadzone)
233233
{
234-
this._edge = this.target.x - this.deadzone.x;
234+
this._edge = this.target.x - this.view.x;
235235

236-
if (this.view.x > this._edge)
236+
if (this._edge < this.deadzone.left)
237237
{
238-
this.view.x = this._edge;
238+
this.view.x = this.target.x - this.deadzone.left;
239239
}
240-
241-
this._edge = this.target.x + this.target.width - this.deadzone.x - this.deadzone.width;
242-
243-
if (this.view.x < this._edge)
240+
else if (this._edge > this.deadzone.right)
244241
{
245-
this.view.x = this._edge;
242+
this.view.x = this.target.x - this.deadzone.right;
246243
}
247244

248-
this._edge = this.target.y - this.deadzone.y;
245+
this._edge = this.target.y - this.view.y;
249246

250-
if (this.view.y > this._edge)
247+
if (this._edge < this.deadzone.top)
251248
{
252-
this.view.y = this._edge;
249+
this.view.y = this.target.y - this.deadzone.top;
253250
}
254-
255-
this._edge = this.target.y + this.target.height - this.deadzone.y - this.deadzone.height;
256-
257-
if (this.view.y < this._edge)
251+
else if (this._edge > this.deadzone.bottom)
258252
{
259-
this.view.y = this._edge;
253+
this.view.y = this.target.y - this.deadzone.bottom;
260254
}
261255
}
262256
else
263257
{
264-
this.focusOnXY(this.target.x, this.target.y);
258+
this.view.x = this.target.x - this.view.halfWidth;
259+
this.view.y = this.target.y - this.view.halfHeight;
265260
}
266261

267262
},

0 commit comments

Comments
 (0)