Skip to content

Commit 9834e9d

Browse files
committed
Added followOffset property to Camera target
1 parent bed3968 commit 9834e9d

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/cameras/2d/Camera.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var Effects = require('./effects');
1111
var EventEmitter = require('eventemitter3');
1212
var Linear = require('../../math/Linear');
1313
var Rectangle = require('../../geom/rectangle/Rectangle');
14+
var SmoothStep = require('../../math/SmoothStep');
1415
var TransformMatrix = require('../../gameobjects/components/TransformMatrix');
1516
var ValueToColor = require('../../display/color/ValueToColor');
1617
var Vector2 = require('../../math/Vector2');
@@ -318,6 +319,16 @@ var Camera = new Class({
318319
*/
319320
this.lerp = new Vector2(1, 1);
320321

322+
/**
323+
* The values stored in this property are added to the follow target position, allowing you to
324+
* offset the camera from the actual target x/y coordinates by the followOffset amount.
325+
*
326+
* @name Phaser.Cameras.Scene2D.Camera#followOffset
327+
* @type {Phaser.Math.Vector2}
328+
* @since 3.9.0
329+
*/
330+
this.followOffset = new Vector2();
331+
321332
/**
322333
* Internal follow target reference.
323334
*
@@ -703,8 +714,8 @@ var Camera = new Class({
703714

704715
if (follow)
705716
{
706-
this.scrollX = Linear(this.scrollX, follow.x - originX, this.lerp.x) / zoom;
707-
this.scrollY = Linear(this.scrollY, follow.y - originY, this.lerp.y) / zoom;
717+
this.scrollX = Linear(this.scrollX, (follow.x - this.followOffset.x) - originX, this.lerp.x) / zoom;
718+
this.scrollY = Linear(this.scrollY, (follow.y - this.followOffset.y) - originY, this.lerp.y) / zoom;
708719
}
709720

710721
if (this.useBounds)

0 commit comments

Comments
 (0)