Merge pull request #5093 from samme/feature/path-follower-delta

Add PathFollower#pathDelta
This commit is contained in:
Richard Davey 2020-04-27 10:12:03 +01:00 committed by GitHub
commit 3147d412f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -70,6 +70,15 @@ var PathFollower = {
*/
pathVector: null,
/**
* The distance the follower has travelled from the previous point to the current one, at the last update.
*
* @name Phaser.GameObjects.PathFollower#pathDelta
* @type {Phaser.Math.Vector2}
* @since 3.23.0
*/
pathDelta: null,
/**
* The Tween used for following the Path.
*
@ -235,6 +244,13 @@ var PathFollower = {
this.pathVector = new Vector2();
}
if (!this.pathDelta)
{
this.pathDelta = new Vector2();
}
this.pathDelta.reset();
this.pathTween = this.scene.sys.tweens.addCounter(config);
// The starting point of the path, relative to this follower
@ -344,14 +360,18 @@ var PathFollower = {
if (tween)
{
var tweenData = tween.data[0];
var pathDelta = this.pathDelta;
var pathVector = this.pathVector;
pathDelta.copy(pathVector).negate();
if (tweenData.state === TWEEN_CONST.COMPLETE)
{
this.path.getPoint(1, pathVector);
pathDelta.add(pathVector);
pathVector.add(this.pathOffset);
this.setPosition(pathVector.x, pathVector.y);
return;
@ -364,6 +384,7 @@ var PathFollower = {
this.path.getPoint(tween.getValue(), pathVector);
pathDelta.add(pathVector);
pathVector.add(this.pathOffset);
var oldX = this.x;