Skip to content

Commit 130988d

Browse files
committed
camera follow
1 parent 1bad881 commit 130988d

1 file changed

Lines changed: 22 additions & 13 deletions

File tree

v3/src/camera/Camera.js

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,22 @@ Camera.prototype = {
101101
}
102102
},
103103

104+
startFollow: function (gameObjectOrPoint)
105+
{
106+
if (this._follow !== null)
107+
{
108+
this.stopFollow();
109+
}
110+
111+
this._follow = gameObjectOrPoint;
112+
},
113+
114+
stopFollow: function ()
115+
{
116+
/* do unfollow work here */
117+
this._follow = null;
118+
},
119+
104120
flash: function (duration, red, green, blue, force)
105121
{
106122
if (!force && this._flashAlpha > 0.0)
@@ -176,26 +192,19 @@ Camera.prototype = {
176192

177193
if (follow != null)
178194
{
179-
if (follow.originX)
180-
{
181-
originX = follow.x + follow.originX;
182-
originY = follow.y + follow.originY;
183-
}
184-
else
185-
{
186-
originX = follow.x;
187-
originY = follow.y;
188-
}
195+
originX = follow.x;
196+
originY = follow.y;
189197

190-
originX = -this.scrollX - originX;
191-
originY = -this.scrollY - originY;
198+
this.scrollX = originX - width * 0.5;
199+
this.scrollY = originY - height * 0.5;
192200
}
193201

194202
matrix.loadIdentity();
195203
matrix.translate(this.x + originX, this.y + originY);
196204
matrix.rotate(this.rotation);
197205
matrix.scale(zoom, zoom);
198-
matrix.translate(-originX + this._shakeOffsetX, -originY + this._shakeOffsetY);
206+
matrix.translate(-originX, -originY);
207+
matrix.translate(this._shakeOffsetX, this._shakeOffsetY);
199208
},
200209

201210
destroy: function ()

0 commit comments

Comments
 (0)