Skip to content

Commit eeb02c6

Browse files
committed
Finished all the new Tween Events
1 parent 5e4e6ca commit eeb02c6

9 files changed

Lines changed: 258 additions & 44 deletions

src/tweens/events/TWEEN_ACTIVE_EVENT.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@
99
*
1010
* This event is dispatched by a Tween when it becomes active within the Tween Manager.
1111
*
12+
* An 'active' Tween is one that is now progressing, although it may not yet be updating
13+
* any target properties, due to settings such as `delay`. If you need an event for when
14+
* the Tween starts actually updating its first property, see `TWEEN_START`.
15+
*
1216
* Listen to it from a Tween instance using `Tween.on('active', listener)`, i.e.:
1317
*
1418
* ```javascript
1519
* var tween = this.tweens.add({
1620
* targets: image,
21+
* x: 500,
1722
* ease: 'Power1',
18-
* duration: 3000,
19-
* tweens: [ { x: 600 }, { y: 500 }, { x: 100 }, { y: 100 } ]
23+
* duration: 3000
2024
* });
2125
* tween.on('active', listener);
2226
* ```
@@ -25,5 +29,6 @@
2529
* @since 3.19.0
2630
*
2731
* @param {Phaser.Tweens.Tween} tween - A reference to the Tween instance that emitted the event.
32+
* @param {any[]} targets - An array of references to the target/s the Tween is operating on.
2833
*/
2934
module.exports = 'active';

src/tweens/events/TWEEN_COMPLETE_EVENT.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@
77
/**
88
* The Tween Complete Event.
99
*
10-
* This event is dispatched by a Tween when it completes playback.
10+
* This event is dispatched by a Tween when it completes playback entirely, factoring in repeats and loops.
11+
*
12+
* If the Tween has been set to loop or repeat infinitely, this event will not be dispatched
13+
* unless the `Tween.stop` method is called.
14+
*
15+
* If a Tween has a `completeDelay` set, this event will fire after that delay expires.
1116
*
1217
* Listen to it from a Tween instance using `Tween.on('complete', listener)`, i.e.:
1318
*
1419
* ```javascript
1520
* var tween = this.tweens.add({
1621
* targets: image,
22+
* x: 500,
1723
* ease: 'Power1',
18-
* duration: 3000,
19-
* tweens: [ { x: 600 }, { y: 500 }, { x: 100 }, { y: 100 } ]
24+
* duration: 3000
2025
* });
2126
* tween.on('complete', listener);
2227
* ```
@@ -25,5 +30,6 @@
2530
* @since 3.19.0
2631
*
2732
* @param {Phaser.Tweens.Tween} tween - A reference to the Tween instance that emitted the event.
33+
* @param {any[]} targets - An array of references to the target/s the Tween is operating on.
2834
*/
2935
module.exports = 'complete';
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2019 Photon Storm Ltd.
4+
* @license {@link https://opensource.org/licenses/MIT|MIT License}
5+
*/
6+
7+
/**
8+
* The Tween Loop Event.
9+
*
10+
* This event is dispatched by a Tween when it loops.
11+
*
12+
* This event will only be dispatched if the Tween has a loop count set.
13+
*
14+
* If a Tween has a `loopDelay` set, this event will fire after that delay expires.
15+
*
16+
* The difference between `loop` and `repeat` is that `repeat` is a property setting,
17+
* where-as `loop` applies to the entire Tween.
18+
*
19+
* Listen to it from a Tween instance using `Tween.on('loop', listener)`, i.e.:
20+
*
21+
* ```javascript
22+
* var tween = this.tweens.add({
23+
* targets: image,
24+
* x: 500,
25+
* ease: 'Power1',
26+
* duration: 3000,
27+
* loop: 6
28+
* });
29+
* tween.on('loop', listener);
30+
* ```
31+
*
32+
* @event Phaser.Tweens.Events#TWEEN_LOOP
33+
* @since 3.19.0
34+
*
35+
* @param {Phaser.Tweens.Tween} tween - A reference to the Tween instance that emitted the event.
36+
* @param {any[]} targets - An array of references to the target/s the Tween is operating on.
37+
*/
38+
module.exports = 'loop';
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2019 Photon Storm Ltd.
4+
* @license {@link https://opensource.org/licenses/MIT|MIT License}
5+
*/
6+
7+
/**
8+
* The Tween Repeat Event.
9+
*
10+
* This event is dispatched by a Tween when one of the properties it is tweening repeats.
11+
*
12+
* This event will only be dispatched if the Tween has a property with a repeat count set.
13+
*
14+
* If a Tween has a `repeatDelay` set, this event will fire after that delay expires.
15+
*
16+
* The difference between `loop` and `repeat` is that `repeat` is a property setting,
17+
* where-as `loop` applies to the entire Tween.
18+
*
19+
* Listen to it from a Tween instance using `Tween.on('repeat', listener)`, i.e.:
20+
*
21+
* ```javascript
22+
* var tween = this.tweens.add({
23+
* targets: image,
24+
* x: 500,
25+
* ease: 'Power1',
26+
* duration: 3000,
27+
* repeat: 4
28+
* });
29+
* tween.on('repeat', listener);
30+
* ```
31+
*
32+
* @event Phaser.Tweens.Events#TWEEN_REPEAT
33+
* @since 3.19.0
34+
*
35+
* @param {Phaser.Tweens.Tween} tween - A reference to the Tween instance that emitted the event.
36+
* @param {string} key - The key of the property that just repeated.
37+
* @param {any} target - The target that the property just repated on.
38+
*/
39+
module.exports = 'repeat';

src/tweens/events/TWEEN_START_EVENT.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,20 @@
77
/**
88
* The Tween Start Event.
99
*
10-
* This event is dispatched by a Tween when it starts playback.
10+
* This event is dispatched by a Tween when it starts tweening its first property.
11+
*
12+
* A Tween will only emit this event once, as it can only start once.
13+
*
14+
* If a Tween has a `delay` set, this event will fire after that delay expires.
1115
*
1216
* Listen to it from a Tween instance using `Tween.on('start', listener)`, i.e.:
1317
*
1418
* ```javascript
1519
* var tween = this.tweens.add({
1620
* targets: image,
21+
* x: 500,
1722
* ease: 'Power1',
18-
* duration: 3000,
19-
* tweens: [ { x: 600 }, { y: 500 }, { x: 100 }, { y: 100 } ]
23+
* duration: 3000
2024
* });
2125
* tween.on('start', listener);
2226
* ```
@@ -25,5 +29,6 @@
2529
* @since 3.19.0
2630
*
2731
* @param {Phaser.Tweens.Tween} tween - A reference to the Tween instance that emitted the event.
32+
* @param {any[]} targets - An array of references to the target/s the Tween is operating on.
2833
*/
2934
module.exports = 'start';
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2019 Photon Storm Ltd.
4+
* @license {@link https://opensource.org/licenses/MIT|MIT License}
5+
*/
6+
7+
/**
8+
* The Tween Update Event.
9+
*
10+
* This event is dispatched by a Tween every time it updates _any_ of the properties it is tweening.
11+
*
12+
* A Tween that is changing 3 properties of a target will emit this event 3 times per change, once per property.
13+
*
14+
* **Note:** This is a very high frequency event and may be dispatched multiple times, every single frame.
15+
*
16+
* Listen to it from a Tween instance using `Tween.on('update', listener)`, i.e.:
17+
*
18+
* ```javascript
19+
* var tween = this.tweens.add({
20+
* targets: image,
21+
* x: 500,
22+
* ease: 'Power1',
23+
* duration: 3000,
24+
* });
25+
* tween.on('update', listener);
26+
* ```
27+
*
28+
* @event Phaser.Tweens.Events#TWEEN_UPDATE
29+
* @since 3.19.0
30+
*
31+
* @param {Phaser.Tweens.Tween} tween - A reference to the Tween instance that emitted the event.
32+
* @param {string} key - The property that was updated, i.e. `x` or `scale`.
33+
* @param {any} target - The target object that was updated. Usually a Game Object, but can be of any type.
34+
*/
35+
module.exports = 'update';
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2019 Photon Storm Ltd.
4+
* @license {@link https://opensource.org/licenses/MIT|MIT License}
5+
*/
6+
7+
/**
8+
* The Tween Yoyo Event.
9+
*
10+
* This event is dispatched by a Tween whenever a property it is tweening yoyos.
11+
*
12+
* This event will only be dispatched if the Tween has a property with `yoyo` set.
13+
*
14+
* If the Tween has a `hold` value, this event is dispatched when the hold expires.
15+
*
16+
* This event is dispatched for every property, and for every target, that yoyos.
17+
* For example, if a Tween was updating 2 properties and had 10 targets, this event
18+
* would be dispatched 20 times (twice per target). So be careful how you use it!
19+
*
20+
* Listen to it from a Tween instance using `Tween.on('yoyo', listener)`, i.e.:
21+
*
22+
* ```javascript
23+
* var tween = this.tweens.add({
24+
* targets: image,
25+
* x: 500,
26+
* ease: 'Power1',
27+
* duration: 3000,
28+
* yoyo: true
29+
* });
30+
* tween.on('yoyo', listener);
31+
* ```
32+
*
33+
* @event Phaser.Tweens.Events#TWEEN_YOYO
34+
* @since 3.19.0
35+
*
36+
* @param {Phaser.Tweens.Tween} tween - A reference to the Tween instance that emitted the event.
37+
* @param {string} key - The property that yoyo'd, i.e. `x` or `scale`.
38+
* @param {any} target - The target object that was yoyo'd. Usually a Game Object, but can be of any type.
39+
*/
40+
module.exports = 'yoyo';

src/tweens/events/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ module.exports = {
1818
TIMELINE_UPDATE: require('./TIMELINE_UPDATE_EVENT'),
1919
TWEEN_ACTIVE: require('./TWEEN_ACTIVE_EVENT'),
2020
TWEEN_COMPLETE: require('./TWEEN_COMPLETE_EVENT'),
21-
TWEEN_START: require('./TWEEN_START_EVENT')
21+
TWEEN_LOOP: require('./TWEEN_LOOP_EVENT'),
22+
TWEEN_REPEAT: require('./TWEEN_REPEAT_EVENT'),
23+
TWEEN_START: require('./TWEEN_START_EVENT'),
24+
TWEEN_UPDATE: require('./TWEEN_UPDATE_EVENT'),
25+
TWEEN_YOYO: require('./TWEEN_YOYO_EVENT')
2226

2327
};

0 commit comments

Comments
 (0)