Skip to content

Commit 03c9c5f

Browse files
committed
Add PathFollower#pathDelta
1 parent 7fbe57c commit 03c9c5f

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

src/gameobjects/components/PathFollower.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ var PathFollower = {
7070
*/
7171
pathVector: null,
7272

73+
/**
74+
* The distance the follower has travelled from the previous point to the current one, at the last update.
75+
*
76+
* @name Phaser.GameObjects.PathFollower#pathDelta
77+
* @type {Phaser.Math.Vector2}
78+
* @since 3.23.0
79+
*/
80+
pathDelta: null,
81+
7382
/**
7483
* The Tween used for following the Path.
7584
*
@@ -235,6 +244,13 @@ var PathFollower = {
235244
this.pathVector = new Vector2();
236245
}
237246

247+
if (!this.pathDelta)
248+
{
249+
this.pathDelta = new Vector2();
250+
}
251+
252+
this.pathDelta.reset();
253+
238254
this.pathTween = this.scene.sys.tweens.addCounter(config);
239255

240256
// The starting point of the path, relative to this follower
@@ -344,14 +360,18 @@ var PathFollower = {
344360
if (tween)
345361
{
346362
var tweenData = tween.data[0];
363+
var pathDelta = this.pathDelta;
347364
var pathVector = this.pathVector;
348365

366+
pathDelta.copy(pathVector).negate();
367+
349368
if (tweenData.state === TWEEN_CONST.COMPLETE)
350369
{
351370
this.path.getPoint(1, pathVector);
352371

372+
pathDelta.add(pathVector);
353373
pathVector.add(this.pathOffset);
354-
374+
355375
this.setPosition(pathVector.x, pathVector.y);
356376

357377
return;
@@ -364,6 +384,7 @@ var PathFollower = {
364384

365385
this.path.getPoint(tween.getValue(), pathVector);
366386

387+
pathDelta.add(pathVector);
367388
pathVector.add(this.pathOffset);
368389

369390
var oldX = this.x;

0 commit comments

Comments
 (0)