Skip to content

Commit 550c9bb

Browse files
committed
Added Timeline Events.
1 parent 33189b4 commit 550c9bb

9 files changed

Lines changed: 215 additions & 7 deletions

src/tweens/Timeline.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
var Class = require('../utils/Class');
88
var EventEmitter = require('eventemitter3');
9+
var Events = require('./events');
910
var TweenBuilder = require('./builders/TweenBuilder');
1011
var TWEEN_CONST = require('./tween/const');
1112

@@ -567,6 +568,7 @@ var Timeline = new Class({
567568
* Starts playing the timeline.
568569
*
569570
* @method Phaser.Tweens.Timeline#play
571+
* @fires Phaser.Tweens.Events#TIMELINE_START
570572
* @since 3.0.0
571573
*/
572574
play: function ()
@@ -598,13 +600,15 @@ var Timeline = new Class({
598600
onStart.func.apply(onStart.scope, onStart.params);
599601
}
600602

601-
this.emit('start', this);
603+
this.emit(Events.TIMELINE_START, this);
602604
},
603605

604606
/**
605607
* [description]
606608
*
607609
* @method Phaser.Tweens.Timeline#nextState
610+
* @fires Phaser.Tweens.Events#TIMELINE_COMPLETE
611+
* @fires Phaser.Tweens.Events#TIMELINE_LOOP
608612
* @since 3.0.0
609613
*/
610614
nextState: function ()
@@ -627,7 +631,7 @@ var Timeline = new Class({
627631
onLoop.func.apply(onLoop.scope, onLoop.params);
628632
}
629633

630-
this.emit('loop', this, this.loopCounter);
634+
this.emit(Events.TIMELINE_LOOP, this, this.loopCounter);
631635

632636
this.resetTweens(true);
633637

@@ -655,7 +659,7 @@ var Timeline = new Class({
655659
onComplete.func.apply(onComplete.scope, onComplete.params);
656660
}
657661

658-
this.emit('complete', this);
662+
this.emit(Events.TIMELINE_COMPLETE, this);
659663

660664
this.state = TWEEN_CONST.PENDING_REMOVE;
661665
}
@@ -666,6 +670,8 @@ var Timeline = new Class({
666670
* Otherwise, returns false.
667671
*
668672
* @method Phaser.Tweens.Timeline#update
673+
* @fires Phaser.Tweens.Events#TIMELINE_COMPLETE
674+
* @fires Phaser.Tweens.Events#TIMELINE_UPDATE
669675
* @since 3.0.0
670676
*
671677
* @param {number} timestamp - [description]
@@ -718,7 +724,7 @@ var Timeline = new Class({
718724
onUpdate.func.apply(onUpdate.scope, onUpdate.params);
719725
}
720726

721-
this.emit('update', this);
727+
this.emit(Events.TIMELINE_UPDATE, this);
722728

723729
// Anything still running? If not, we're done
724730
if (stillRunning === 0)
@@ -752,7 +758,7 @@ var Timeline = new Class({
752758
onComplete.func.apply(onComplete.scope, onComplete.params);
753759
}
754760

755-
this.emit('complete', this);
761+
this.emit(Events.TIMELINE_COMPLETE, this);
756762

757763
this.state = TWEEN_CONST.PENDING_REMOVE;
758764
}
@@ -778,6 +784,7 @@ var Timeline = new Class({
778784
* Pauses the timeline, retaining its internal state.
779785
*
780786
* @method Phaser.Tweens.Timeline#pause
787+
* @fires Phaser.Tweens.Events#TIMELINE_PAUSE
781788
* @since 3.0.0
782789
*
783790
* @return {Phaser.Tweens.Timeline} This Timeline object.
@@ -795,7 +802,7 @@ var Timeline = new Class({
795802

796803
this.state = TWEEN_CONST.PAUSED;
797804

798-
this.emit('pause', this);
805+
this.emit(Events.TIMELINE_PAUSE, this);
799806

800807
return this;
801808
},
@@ -804,6 +811,7 @@ var Timeline = new Class({
804811
* Resumes the timeline from where it was when it was paused.
805812
*
806813
* @method Phaser.Tweens.Timeline#resume
814+
* @fires Phaser.Tweens.Events#TIMELINE_RESUME
807815
* @since 3.0.0
808816
*
809817
* @return {Phaser.Tweens.Timeline} This Timeline object.
@@ -817,7 +825,7 @@ var Timeline = new Class({
817825
this.state = this._pausedState;
818826
}
819827

820-
this.emit('resume', this);
828+
this.emit(Events.TIMELINE_RESUME, this);
821829

822830
return this;
823831
},
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2019 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
/**
8+
* The Timeline Complete Event.
9+
*
10+
* This event is dispatched by a Tween Timeline when it completes playback.
11+
*
12+
* Listen to it from a Timeline instance using `Timeline.on('complete', listener)`, i.e.:
13+
*
14+
* ```javascript
15+
* var timeline = this.tweens.timeline({
16+
* targets: image,
17+
* ease: 'Power1',
18+
* duration: 3000,
19+
* tweens: [ { x: 600 }, { y: 500 }, { x: 100 }, { y: 100 } ]
20+
* });
21+
* timeline.on('complete', listener);
22+
* timeline.play();
23+
* ```
24+
*
25+
* @event Phaser.Tweens.Events#TIMELINE_COMPLETE
26+
*
27+
* @param {Phaser.Tweens.Timeline} timeline - A reference to the Timeline instance that emitted the event.
28+
*/
29+
module.exports = 'complete';
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2019 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
/**
8+
* The Timeline Loop Event.
9+
*
10+
* This event is dispatched by a Tween Timeline every time it loops.
11+
*
12+
* Listen to it from a Timeline instance using `Timeline.on('loop', listener)`, i.e.:
13+
*
14+
* ```javascript
15+
* var timeline = this.tweens.timeline({
16+
* targets: image,
17+
* ease: 'Power1',
18+
* duration: 3000,
19+
* loop: 4,
20+
* tweens: [ { x: 600 }, { y: 500 }, { x: 100 }, { y: 100 } ]
21+
* });
22+
* timeline.on('loop', listener);
23+
* timeline.play();
24+
* ```
25+
*
26+
* @event Phaser.Tweens.Events#TIMELINE_LOOP
27+
*
28+
* @param {Phaser.Tweens.Timeline} timeline - A reference to the Timeline instance that emitted the event.
29+
* @param {integer} loopCount - The number of loops left before this Timeline completes.
30+
*/
31+
module.exports = 'loop';
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2019 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
/**
8+
* The Timeline Pause Event.
9+
*
10+
* This event is dispatched by a Tween Timeline when it is paused.
11+
*
12+
* Listen to it from a Timeline instance using `Timeline.on('pause', listener)`, i.e.:
13+
*
14+
* ```javascript
15+
* var timeline = this.tweens.timeline({
16+
* targets: image,
17+
* ease: 'Power1',
18+
* duration: 3000,
19+
* tweens: [ { x: 600 }, { y: 500 }, { x: 100 }, { y: 100 } ]
20+
* });
21+
* timeline.on('pause', listener);
22+
* // At some point later ...
23+
* timeline.pause();
24+
* ```
25+
*
26+
* @event Phaser.Tweens.Events#TIMELINE_PAUSE
27+
*
28+
* @param {Phaser.Tweens.Timeline} timeline - A reference to the Timeline instance that emitted the event.
29+
*/
30+
module.exports = 'pause';
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2019 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
/**
8+
* The Timeline Resume Event.
9+
*
10+
* This event is dispatched by a Tween Timeline when it is resumed from a paused state.
11+
*
12+
* Listen to it from a Timeline instance using `Timeline.on('resume', listener)`, i.e.:
13+
*
14+
* ```javascript
15+
* var timeline = this.tweens.timeline({
16+
* targets: image,
17+
* ease: 'Power1',
18+
* duration: 3000,
19+
* tweens: [ { x: 600 }, { y: 500 }, { x: 100 }, { y: 100 } ]
20+
* });
21+
* timeline.on('resume', listener);
22+
* // At some point later ...
23+
* timeline.resume();
24+
* ```
25+
*
26+
* @event Phaser.Tweens.Events#TIMELINE_RESUME
27+
*
28+
* @param {Phaser.Tweens.Timeline} timeline - A reference to the Timeline instance that emitted the event.
29+
*/
30+
module.exports = 'resume';
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2019 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
/**
8+
* The Timeline Start Event.
9+
*
10+
* This event is dispatched by a Tween Timeline when it starts.
11+
*
12+
* Listen to it from a Timeline instance using `Timeline.on('start', listener)`, i.e.:
13+
*
14+
* ```javascript
15+
* var timeline = this.tweens.timeline({
16+
* targets: image,
17+
* ease: 'Power1',
18+
* duration: 3000,
19+
* tweens: [ { x: 600 }, { y: 500 }, { x: 100 }, { y: 100 } ]
20+
* });
21+
* timeline.on('start', listener);
22+
* timeline.play();
23+
* ```
24+
*
25+
* @event Phaser.Tweens.Events#TIMELINE_START
26+
*
27+
* @param {Phaser.Tweens.Timeline} timeline - A reference to the Timeline instance that emitted the event.
28+
*/
29+
module.exports = 'start';
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2019 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
/**
8+
* The Timeline Update Event.
9+
*
10+
* This event is dispatched by a Tween Timeline every time it updates, which can happen a lot of times per second,
11+
* so be careful about listening to this event unless you absolutely require it.
12+
*
13+
* Listen to it from a Timeline instance using `Timeline.on('update', listener)`, i.e.:
14+
*
15+
* ```javascript
16+
* var timeline = this.tweens.timeline({
17+
* targets: image,
18+
* ease: 'Power1',
19+
* duration: 3000,
20+
* tweens: [ { x: 600 }, { y: 500 }, { x: 100 }, { y: 100 } ]
21+
* });
22+
* timeline.on('update', listener);
23+
* timeline.play();
24+
* ```
25+
*
26+
* @event Phaser.Tweens.Events#TIMELINE_UPDATE
27+
*
28+
* @param {Phaser.Tweens.Timeline} timeline - A reference to the Timeline instance that emitted the event.
29+
*/
30+
module.exports = 'update';

src/tweens/events/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2019 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
/**
8+
* @namespace Phaser.Tweens.Events
9+
*/
10+
11+
module.exports = {
12+
13+
TIMELINE_COMPLETE: require('./TIMELINE_COMPLETE_EVENT'),
14+
TIMELINE_LOOP: require('./TIMELINE_LOOP_EVENT'),
15+
TIMELINE_PAUSE: require('./TIMELINE_PAUSE_EVENT'),
16+
TIMELINE_RESUME: require('./TIMELINE_RESUME_EVENT'),
17+
TIMELINE_START: require('./TIMELINE_START_EVENT'),
18+
TIMELINE_UPDATE: require('./TIMELINE_UPDATE_EVENT')
19+
20+
};

src/tweens/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var Extend = require('../utils/object/Extend');
1414
var Tweens = {
1515

1616
Builders: require('./builders'),
17+
Events: require('./events'),
1718

1819
TweenManager: require('./TweenManager'),
1920
Tween: require('./tween/Tween'),

0 commit comments

Comments
 (0)