Skip to content

Commit 7b7d897

Browse files
authored
Merge pull request phaserjs#5185 from samme/feature/tween-stop-event
Add tween 'stop' event and 'onStop' callback
2 parents 853feea + 51779a8 commit 7b7d897

7 files changed

Lines changed: 54 additions & 1 deletion

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @author samme
3+
* @copyright 2020 Photon Storm Ltd.
4+
* @license {@link https://opensource.org/licenses/MIT|MIT License}
5+
*/
6+
7+
/**
8+
* The Tween Stop Event.
9+
*
10+
* This event is dispatched by a Tween when it is stopped.
11+
*
12+
* Listen to it from a Tween instance using `Tween.on('stop', listener)`, i.e.:
13+
*
14+
* ```javascript
15+
* var tween = this.tweens.add({
16+
* targets: image,
17+
* x: 500,
18+
* ease: 'Power1',
19+
* duration: 3000
20+
* });
21+
* tween.on('stop', listener);
22+
* ```
23+
*
24+
* @event Phaser.Tweens.Events#TWEEN_STOP
25+
* @since 3.24.0
26+
*
27+
* @param {Phaser.Tweens.Tween} tween - A reference to the Tween instance that emitted the event.
28+
* @param {any[]} targets - An array of references to the target/s the Tween is operating on.
29+
*/
30+
module.exports = 'stop';

src/tweens/events/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module.exports = {
2121
TWEEN_LOOP: require('./TWEEN_LOOP_EVENT'),
2222
TWEEN_REPEAT: require('./TWEEN_REPEAT_EVENT'),
2323
TWEEN_START: require('./TWEEN_START_EVENT'),
24+
TWEEN_STOP: require('./TWEEN_STOP_EVENT'),
2425
TWEEN_UPDATE: require('./TWEEN_UPDATE_EVENT'),
2526
TWEEN_YOYO: require('./TWEEN_YOYO_EVENT')
2627

src/tweens/tween/ReservedProps.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// flipY: flip Y the GameObject on tween end// hold: The time the tween will pause before running a yoyo
1616
// hold: The time the tween will pause before running a yoyo
1717
// loop: The time the tween will pause before starting either a yoyo or returning to the start for a repeat
18-
// loopDelay:
18+
// loopDelay:
1919
// offset: Used when the Tween is part of a Timeline
2020
// paused: Does the tween start in a paused state, or playing?
2121
// props: The properties being tweened by the tween
@@ -53,6 +53,9 @@ module.exports = [
5353
'onStart',
5454
'onStartParams',
5555
'onStartScope',
56+
'onStop',
57+
'onStopParams',
58+
'onStopScope',
5659
'onUpdate',
5760
'onUpdateParams',
5861
'onUpdateScope',

src/tweens/tween/Tween.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ var Tween = new Class({
331331
onLoop: null,
332332
onRepeat: null,
333333
onStart: null,
334+
onStop: null,
334335
onUpdate: null,
335336
onYoyo: null
336337
};
@@ -1107,6 +1108,8 @@ var Tween = new Class({
11071108
}
11081109
}
11091110

1111+
this.dispatchTweenEvent(Events.TWEEN_STOP, this.callbacks.onStop);
1112+
11101113
this.removeAllListeners();
11111114

11121115
this.state = TWEEN_CONST.PENDING_REMOVE;
@@ -1575,6 +1578,7 @@ var Tween = new Class({
15751578

15761579
// onActive = 'active' event = When the Tween is moved from the pending to the active list in the manager, even if playback delayed
15771580
// onStart = 'start' event = When the Tween starts playing from a delayed state (will happen same time as onActive if no delay)
1581+
// onStop = 'stop' event = When the Tween is stopped
15781582
// onYoyo = 'yoyo' event = When the Tween starts a yoyo
15791583
// onRepeat = 'repeat' event = When a TweenData repeats playback (if any)
15801584
// onComplete = 'complete' event = When the Tween finishes all playback (can sometimes never happen if repeat -1), also when 'stop' called
@@ -1587,6 +1591,7 @@ Tween.TYPES = [
15871591
'onLoop',
15881592
'onRepeat',
15891593
'onStart',
1594+
'onStop',
15901595
'onUpdate',
15911596
'onYoyo'
15921597
];

src/tweens/typedefs/NumberTweenBuilderConfig.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
* @property {Phaser.Types.Tweens.TweenOnStartCallback} [onStart] - A function to call when the tween starts.
3232
* @property {array} [onStartParams] - Additional parameters to pass to `onStart`.
3333
* @property {any} [onStartScope] - Scope (this) for `onStart`.
34+
* @property {Phaser.Types.Tweens.TweenOnStopCallback} [onStop] - A function to call when the tween is stopped.
35+
* @property {array} [onStopParams] - Additional parameters to pass to `onStop`.
36+
* @property {any} [onStopScope] - Scope (this) for `onStop`.
3437
* @property {Phaser.Types.Tweens.TweenOnUpdateCallback} [onUpdate] - A function to call each time the tween steps. Called once per property per target.
3538
* @property {array} [onUpdateParams] - Additional parameters to pass to `onUpdate`.
3639
* @property {any} [onUpdateScope] - Scope (this) for `onUpdate`.

src/tweens/typedefs/TweenBuilderConfig.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
* @property {Phaser.Types.Tweens.TweenOnStartCallback} [onStart] - A function to call when the tween starts playback, after any delays have expired.
3434
* @property {array} [onStartParams] - Additional parameters to pass to `onStart`.
3535
* @property {any} [onStartScope] - Scope (this) for `onStart`.
36+
* @property {Phaser.Types.Tweens.TweenOnStopCallback} [onStop] - A function to call when the tween is stopped.
37+
* @property {array} [onStopParams] - Additional parameters to pass to `onStop`.
38+
* @property {any} [onStopScope] - Scope (this) for `onStop`.
3639
* @property {Phaser.Types.Tweens.TweenOnUpdateCallback} [onUpdate] - A function to call each time the tween steps. Called once per property per target.
3740
* @property {array} [onUpdateParams] - Additional parameters to pass to `onUpdate`.
3841
* @property {any} [onUpdateScope] - Scope (this) for `onUpdate`.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @callback Phaser.Types.Tweens.TweenOnStopCallback
3+
* @since 3.24.0
4+
*
5+
* @param {Phaser.Tweens.Tween} tween - The tween.
6+
* @param {array} targets - The tween targets.
7+
* @param {...any} param - Any value passed in `onStopParams`.
8+
*/

0 commit comments

Comments
 (0)