Skip to content

Commit a34824c

Browse files
committed
Planning new vStart cache.
1 parent 64cf3a6 commit a34824c

2 files changed

Lines changed: 74 additions & 22 deletions

File tree

src/tween/Tween.js

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,29 @@ Phaser.Tween = function (target, game, manager) {
7878
this.onStart = new Phaser.Signal();
7979

8080
/**
81-
* The onLoop event is fired if the Tween loops. If there are chained tweens it fires after all the child tweens have completed.
81+
* The onLoop event is fired if the Tween or any child tween loops.
8282
* It will be sent 2 parameters: the target object and this tween.
8383
* @property {Phaser.Signal} onLoop
8484
*/
8585
this.onLoop = new Phaser.Signal();
8686

8787
/**
88-
* The onComplete event is fired when the Tween completes. Does not fire if the Tween is set to loop or repeatAll(-1).
88+
* The onRepeat event is fired if the Tween and all of its children repeats. If this tween has no children this will never be fired.
89+
* It will be sent 2 parameters: the target object and this tween.
90+
* @property {Phaser.Signal} onRepeat
91+
*/
92+
this.onRepeat = new Phaser.Signal();
93+
94+
/**
95+
* The onChildComplete event is fired when the Tween or any of its children completes.
96+
* Fires every time a child completes unless a child is set to repeat forever.
97+
* It will be sent 2 parameters: the target object and this tween.
98+
* @property {Phaser.Signal} onChildComplete
99+
*/
100+
this.onChildComplete = new Phaser.Signal();
101+
102+
/**
103+
* The onComplete event is fired when the Tween and all of its children completes. Does not fire if the Tween is set to loop or repeatAll(-1).
89104
* It will be sent 2 parameters: the target object and this tween.
90105
* @property {Phaser.Signal} onComplete
91106
*/
@@ -646,41 +661,61 @@ Phaser.Tween.prototype = {
646661
}
647662
else if (status === Phaser.TweenData.COMPLETE)
648663
{
664+
var complete = false;
665+
649666
// What now?
650667
if (this.reverse)
651668
{
652669
this.current--;
670+
671+
if (this.current < 0)
672+
{
673+
this.current = this.timeline.length - 1;
674+
complete = true;
675+
}
653676
}
654677
else
655678
{
656679
this.current++;
680+
681+
if (this.current === this.timeline.length)
682+
{
683+
this.current = 0;
684+
complete = true;
685+
}
657686
}
658687

659-
if (this.repeatCounter === -1 || this.repeatCounter > 0)
688+
if (complete)
660689
{
661-
if (this.repeatCounter !== -1)
690+
// We've reached the start or end of the child tweens (depending on Tween.reverse), should we repeat it?
691+
if (this.repeatCounter === -1)
662692
{
663-
this.repeatCounter--;
693+
this.timeline[this.current].start();
694+
this.onRepeat.dispatch(this.target, this);
695+
return true;
664696
}
665-
666-
if (this.current < 0)
697+
else if (this.repeatCounter > 0)
667698
{
668-
this.current = this.timeline.length - 1;
699+
this.repeatCounter--;
700+
701+
this.timeline[this.current].start();
702+
this.onRepeat.dispatch(this.target, this);
703+
return true;
669704
}
670-
else if (this.current === this.timeline.length)
705+
else
671706
{
672-
this.current = 0;
707+
// No more repeats and no more children, so we're done
708+
this.isRunning = false;
709+
this.onComplete.dispatch(this.target, this);
710+
return false;
673711
}
674-
675-
this.timeline[this.current].start();
676-
return true;
677712
}
678713
else
679714
{
680-
// And we're done
681-
this.isRunning = false;
682-
this.onComplete.dispatch(this.target, this);
683-
return false;
715+
// We've still got some children to go
716+
this.onChildComplete.dispatch(this.target, this);
717+
this.timeline[this.current].start();
718+
return true;
684719
}
685720
}
686721

src/tween/TweenData.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,6 @@ Phaser.TweenData.prototype = {
207207
*/
208208
loadValues: function () {
209209

210-
this.isRunning = true;
211-
this.dt = 0;
212-
this.yoyoCounter = 0;
213-
214210
for (var property in this.vEnd)
215211
{
216212
// Check if an Array was provided as property value
@@ -242,6 +238,20 @@ Phaser.TweenData.prototype = {
242238
this.vEndCache[property] = this.vEnd[property];
243239
}
244240

241+
if (this.parent.reverse)
242+
{
243+
this.dt = this.duration;
244+
}
245+
else
246+
{
247+
this.dt = 0;
248+
}
249+
250+
this.isRunning = true;
251+
this.yoyoCounter = 0;
252+
253+
console.log('loadValues', this.dt, this.vStart, this.vEnd);
254+
245255
return this;
246256

247257
},
@@ -362,7 +372,14 @@ Phaser.TweenData.prototype = {
362372

363373
this.startTime = this.game.time.time + this.delay;
364374

365-
this.dt = 0;
375+
if (this.parent.reverse)
376+
{
377+
this.dt = this.duration;
378+
}
379+
else
380+
{
381+
this.dt = 0;
382+
}
366383

367384
return Phaser.TweenData.LOOPED;
368385

0 commit comments

Comments
 (0)