mirror of
https://github.com/photonstorm/phaser
synced 2025-02-16 22:18:29 +00:00
Merge pull request #5093 from samme/feature/path-follower-delta
Add PathFollower#pathDelta
This commit is contained in:
commit
3147d412f9
1 changed files with 22 additions and 1 deletions
|
@ -70,6 +70,15 @@ var PathFollower = {
|
||||||
*/
|
*/
|
||||||
pathVector: null,
|
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.
|
* The Tween used for following the Path.
|
||||||
*
|
*
|
||||||
|
@ -235,6 +244,13 @@ var PathFollower = {
|
||||||
this.pathVector = new Vector2();
|
this.pathVector = new Vector2();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.pathDelta)
|
||||||
|
{
|
||||||
|
this.pathDelta = new Vector2();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.pathDelta.reset();
|
||||||
|
|
||||||
this.pathTween = this.scene.sys.tweens.addCounter(config);
|
this.pathTween = this.scene.sys.tweens.addCounter(config);
|
||||||
|
|
||||||
// The starting point of the path, relative to this follower
|
// The starting point of the path, relative to this follower
|
||||||
|
@ -344,14 +360,18 @@ var PathFollower = {
|
||||||
if (tween)
|
if (tween)
|
||||||
{
|
{
|
||||||
var tweenData = tween.data[0];
|
var tweenData = tween.data[0];
|
||||||
|
var pathDelta = this.pathDelta;
|
||||||
var pathVector = this.pathVector;
|
var pathVector = this.pathVector;
|
||||||
|
|
||||||
|
pathDelta.copy(pathVector).negate();
|
||||||
|
|
||||||
if (tweenData.state === TWEEN_CONST.COMPLETE)
|
if (tweenData.state === TWEEN_CONST.COMPLETE)
|
||||||
{
|
{
|
||||||
this.path.getPoint(1, pathVector);
|
this.path.getPoint(1, pathVector);
|
||||||
|
|
||||||
|
pathDelta.add(pathVector);
|
||||||
pathVector.add(this.pathOffset);
|
pathVector.add(this.pathOffset);
|
||||||
|
|
||||||
this.setPosition(pathVector.x, pathVector.y);
|
this.setPosition(pathVector.x, pathVector.y);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -364,6 +384,7 @@ var PathFollower = {
|
||||||
|
|
||||||
this.path.getPoint(tween.getValue(), pathVector);
|
this.path.getPoint(tween.getValue(), pathVector);
|
||||||
|
|
||||||
|
pathDelta.add(pathVector);
|
||||||
pathVector.add(this.pathOffset);
|
pathVector.add(this.pathOffset);
|
||||||
|
|
||||||
var oldX = this.x;
|
var oldX = this.x;
|
||||||
|
|
Loading…
Add table
Reference in a new issue