Skip to content

Commit 4d2e603

Browse files
committed
fix camera follow when in a scaled parent
1 parent ff034b5 commit 4d2e603

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

src/core/Camera.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ Phaser.Camera = function (game, id, x, y, width, height) {
109109
*/
110110
this.scale = null;
111111

112+
/**
113+
* @property {Phaser.Point} _targetPosition - Internal point used to calculate target position
114+
*/
115+
this._targetPosition = new Phaser.Point();
116+
112117
};
113118

114119
/**
@@ -247,34 +252,41 @@ Phaser.Camera.prototype = {
247252
*/
248253
updateTarget: function () {
249254

255+
this._targetPosition
256+
.copyFrom(this.target)
257+
.multiply(
258+
this.target.parent ? this.target.parent.worldTransform.a : 1,
259+
this.target.parent ? this.target.parent.worldTransform.d : 1
260+
);
261+
250262
if (this.deadzone)
251263
{
252-
this._edge = this.target.x - this.view.x;
264+
this._edge = this._targetPosition.x - this.view.x;
253265

254266
if (this._edge < this.deadzone.left)
255267
{
256-
this.view.x = this.target.x - this.deadzone.left;
268+
this.view.x = this._targetPosition.x - this.deadzone.left;
257269
}
258270
else if (this._edge > this.deadzone.right)
259271
{
260-
this.view.x = this.target.x - this.deadzone.right;
272+
this.view.x = this._targetPosition.x - this.deadzone.right;
261273
}
262274

263-
this._edge = this.target.y - this.view.y;
275+
this._edge = this._targetPosition.y - this.view.y;
264276

265277
if (this._edge < this.deadzone.top)
266278
{
267-
this.view.y = this.target.y - this.deadzone.top;
279+
this.view.y = this._targetPosition.y - this.deadzone.top;
268280
}
269281
else if (this._edge > this.deadzone.bottom)
270282
{
271-
this.view.y = this.target.y - this.deadzone.bottom;
283+
this.view.y = this._targetPosition.y - this.deadzone.bottom;
272284
}
273285
}
274286
else
275287
{
276-
this.view.x = this.target.x - this.view.halfWidth;
277-
this.view.y = this.target.y - this.view.halfHeight;
288+
this.view.x = this._targetPosition.x - this.view.halfWidth;
289+
this.view.y = this._targetPosition.y - this.view.halfHeight;
278290
}
279291

280292
},

0 commit comments

Comments
 (0)