Skip to content

Commit bbbae64

Browse files
committed
Deleted un-used events, renamed Sprite events and added lots more documentation.
1 parent 47f5cec commit bbbae64

19 files changed

Lines changed: 142 additions & 345 deletions

src/animations/events/ANIMATION_COMPLETE_EVENT.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,34 @@
66

77
/**
88
* The Animation Complete Event.
9-
*
10-
* This event is dispatched by an Animation instance when it completes, i.e. finishes playing or is manually stopped.
11-
*
12-
* Be careful with the volume of events this could generate. If a group of Sprites all complete the same
13-
* animation at the same time, this event will invoke its handler for each one of them.
9+
*
10+
* This event is dispatched by a Sprite when an animation playing on it completes playback.
11+
* This happens when the animation gets to the end of its sequence, factoring in any delays
12+
* or repeats it may have to process.
13+
*
14+
* An animation that is set to loop, or repeat forever, will never fire this event, because
15+
* it never actually completes. If you need to handle this, listen for the `ANIMATION_STOP`
16+
* event instead, as this is emitted when the animation is stopped directly.
17+
*
18+
* Listen for it on the Sprite using `sprite.on('animationcomplete', listener)`
19+
*
20+
* The animation event flow is as follows:
21+
*
22+
* 1. `ANIMATION_START`
23+
* 2. `ANIMATION_UPDATE` (repeated for however many frames the animation has)
24+
* 3. `ANIMATION_REPEAT` (only if the animation is set to repeat, it then emits more update events after this)
25+
* 4. `ANIMATION_COMPLETE` (only if there is a finite, or zero, repeat count)
26+
*
27+
* If the animation is stopped directly, the `ANIMATION_STOP` event is dispatched instead of `ANIMATION_COMPLETE`.
28+
*
29+
* If the animation is restarted while it is already playing, `ANIMATION_RESTART` is emitted.
1430
*
1531
* @event Phaser.Animations.Events#ANIMATION_COMPLETE
16-
* @since 3.16.1
17-
*
32+
* @since 3.50.0
33+
*
1834
* @param {Phaser.Animations.Animation} animation - A reference to the Animation that completed.
19-
* @param {Phaser.Animations.AnimationFrame} frame - The current Animation Frame that the Animation completed on.
20-
* @param {Phaser.GameObjects.Sprite} gameObject - A reference to the Game Object on which the animation completed.
35+
* @param {Phaser.Animations.AnimationFrame} frame - The current Animation Frame of the Animation.
36+
* @param {Phaser.GameObjects.Sprite} gameObject - A reference to the Game Object on which the animation updated.
37+
* @param {string} frameKey - The unique key of the Animation Frame within the Animation.
2138
*/
22-
module.exports = 'complete';
39+
module.exports = 'animationcomplete';

src/animations/events/ANIMATION_REPEAT_EVENT.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,31 @@
66

77
/**
88
* The Animation Repeat Event.
9-
*
10-
* This event is dispatched when a currently playing animation repeats.
11-
*
12-
* The event is dispatched directly from the Animation object itself. Which means that listeners
13-
* bound to this event will be invoked every time the Animation repeats, for every Game Object that may have it.
9+
*
10+
* This event is dispatched by a Sprite when an animation repeats playing on it.
11+
* This happens if the animation was created, or played, with a `repeat` value specified.
12+
*
13+
* An animation will repeat when it reaches the end of its sequence.
14+
*
15+
* Listen for it on the Sprite using `sprite.on('animationrepeat', listener)`
16+
*
17+
* The animation event flow is as follows:
18+
*
19+
* 1. `ANIMATION_START`
20+
* 2. `ANIMATION_UPDATE` (repeated for however many frames the animation has)
21+
* 3. `ANIMATION_REPEAT` (only if the animation is set to repeat, it then emits more update events after this)
22+
* 4. `ANIMATION_COMPLETE` (only if there is a finite, or zero, repeat count)
23+
*
24+
* If the animation is stopped directly, the `ANIMATION_STOP` event is dispatched instead of `ANIMATION_COMPLETE`.
25+
*
26+
* If the animation is restarted while it is already playing, `ANIMATION_RESTART` is emitted.
1427
*
1528
* @event Phaser.Animations.Events#ANIMATION_REPEAT
16-
* @since 3.16.1
17-
*
18-
* @param {Phaser.Animations.Animation} animation - A reference to the Animation that repeated.
19-
* @param {Phaser.Animations.AnimationFrame} frame - The current Animation Frame that the Animation was on when it repeated.
29+
* @since 3.50.0
30+
*
31+
* @param {Phaser.Animations.Animation} animation - A reference to the Animation that has repeated.
32+
* @param {Phaser.Animations.AnimationFrame} frame - The current Animation Frame of the Animation.
33+
* @param {Phaser.GameObjects.Sprite} gameObject - A reference to the Game Object on which the animation repeated.
34+
* @param {string} frameKey - The unique key of the Animation Frame within the Animation.
2035
*/
21-
module.exports = 'repeat';
36+
module.exports = 'animationrepeat';

src/animations/events/ANIMATION_RESTART_EVENT.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,29 @@
66

77
/**
88
* The Animation Restart Event.
9-
*
10-
* This event is dispatched by an Animation instance when it restarts.
11-
*
12-
* Be careful with the volume of events this could generate. If a group of Sprites all restart the same
13-
* animation at the same time, this event will invoke its handler for each one of them.
9+
*
10+
* This event is dispatched by a Sprite when an animation restarts playing on it.
11+
* This only happens when the `Sprite.anims.restart` method is called.
12+
*
13+
* Listen for it on the Sprite using `sprite.on('animationrestart', listener)`
14+
*
15+
* The animation event flow is as follows:
16+
*
17+
* 1. `ANIMATION_START`
18+
* 2. `ANIMATION_UPDATE` (repeated for however many frames the animation has)
19+
* 3. `ANIMATION_REPEAT` (only if the animation is set to repeat, it then emits more update events after this)
20+
* 4. `ANIMATION_COMPLETE` (only if there is a finite, or zero, repeat count)
21+
*
22+
* If the animation is stopped directly, the `ANIMATION_STOP` event is dispatched instead of `ANIMATION_COMPLETE`.
23+
*
24+
* If the animation is restarted while it is already playing, `ANIMATION_RESTART` is emitted.
1425
*
1526
* @event Phaser.Animations.Events#ANIMATION_RESTART
16-
* @since 3.16.1
17-
*
18-
* @param {Phaser.Animations.Animation} animation - A reference to the Animation that restarted playing.
19-
* @param {Phaser.Animations.AnimationFrame} frame - The current Animation Frame that the Animation restarted with.
20-
* @param {Phaser.GameObjects.Sprite} gameObject - A reference to the Game Object on which the animation restarted playing.
27+
* @since 3.50.0
28+
*
29+
* @param {Phaser.Animations.Animation} animation - A reference to the Animation that has restarted.
30+
* @param {Phaser.Animations.AnimationFrame} frame - The current Animation Frame of the Animation.
31+
* @param {Phaser.GameObjects.Sprite} gameObject - A reference to the Game Object on which the animation restarted.
32+
* @param {string} frameKey - The unique key of the Animation Frame within the Animation.
2133
*/
22-
module.exports = 'restart';
34+
module.exports = 'animationrestart';

src/animations/events/ANIMATION_START_EVENT.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,30 @@
66

77
/**
88
* The Animation Start Event.
9-
*
10-
* This event is dispatched by an Animation instance when it starts playing.
11-
*
12-
* Be careful with the volume of events this could generate. If a group of Sprites all play the same
13-
* animation at the same time, this event will invoke its handler for each one of them.
9+
*
10+
* This event is dispatched by a Sprite when an animation starts playing on it.
11+
* This happens when the animation is played, factoring in any delay that may have been specified.
12+
* This event happens after the delay has expired and prior to the first update event.
13+
*
14+
* Listen for it on the Sprite using `sprite.on('animationstart', listener)`
15+
*
16+
* The animation event flow is as follows:
17+
*
18+
* 1. `ANIMATION_START`
19+
* 2. `ANIMATION_UPDATE` (repeated for however many frames the animation has)
20+
* 3. `ANIMATION_REPEAT` (only if the animation is set to repeat, it then emits more update events after this)
21+
* 4. `ANIMATION_COMPLETE` (only if there is a finite, or zero, repeat count)
22+
*
23+
* If the animation is stopped directly, the `ANIMATION_STOP` event is dispatched instead of `ANIMATION_COMPLETE`.
24+
*
25+
* If the animation is restarted while it is already playing, `ANIMATION_RESTART` is emitted.
1426
*
1527
* @event Phaser.Animations.Events#ANIMATION_START
16-
* @since 3.16.1
17-
*
18-
* @param {Phaser.Animations.Animation} animation - A reference to the Animation that started playing.
19-
* @param {Phaser.Animations.AnimationFrame} frame - The current Animation Frame that the Animation started with.
20-
* @param {Phaser.GameObjects.Sprite} gameObject - A reference to the Game Object on which the animation started playing.
28+
* @since 3.50.0
29+
*
30+
* @param {Phaser.Animations.Animation} animation - A reference to the Animation that has started.
31+
* @param {Phaser.Animations.AnimationFrame} frame - The current Animation Frame of the Animation.
32+
* @param {Phaser.GameObjects.Sprite} gameObject - A reference to the Game Object on which the animation started.
33+
* @param {string} frameKey - The unique key of the Animation Frame within the Animation.
2134
*/
22-
module.exports = 'start';
35+
module.exports = 'animationstart';

src/animations/events/ANIMATION_STOP_EVENT.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,29 @@
77
/**
88
* The Animation Stop Event.
99
*
10-
* This event is dispatched by an Animation instance when playback is forcibly stopped on it,
11-
* i.e. `Sprite.stop()`, or similar, is called. Or, a new animation is started before the
12-
* previous one completes.
10+
* This event is dispatched by a Sprite when an animation is stopped on it. An animation
11+
* will only be stopeed if a method such as `Sprite.stop` or `Sprite.anims.stopAfterDelay`
12+
* is called. It can also be emitted if a new animation is started before the current one completes.
13+
*
14+
* Listen for it on the Sprite using `sprite.on('animationstop', listener)`
15+
*
16+
* The animation event flow is as follows:
17+
*
18+
* 1. `ANIMATION_START`
19+
* 2. `ANIMATION_UPDATE` (repeated for however many frames the animation has)
20+
* 3. `ANIMATION_REPEAT` (only if the animation is set to repeat, it then emits more update events after this)
21+
* 4. `ANIMATION_COMPLETE` (only if there is a finite, or zero, repeat count)
22+
*
23+
* If the animation is stopped directly, the `ANIMATION_STOP` event is dispatched instead of `ANIMATION_COMPLETE`.
24+
*
25+
* If the animation is restarted while it is already playing, `ANIMATION_RESTART` is emitted.
1326
*
1427
* @event Phaser.Animations.Events#ANIMATION_STOP
1528
* @since 3.50.0
1629
*
17-
* @param {Phaser.Animations.Animation} animation - A reference to the Animation that was stopped.
18-
* @param {Phaser.Animations.AnimationFrame} frame - The current Animation Frame that the Animation stopped on.
30+
* @param {Phaser.Animations.Animation} animation - A reference to the Animation that has stopped.
31+
* @param {Phaser.Animations.AnimationFrame} frame - The current Animation Frame of the Animation.
1932
* @param {Phaser.GameObjects.Sprite} gameObject - A reference to the Game Object on which the animation stopped.
33+
* @param {string} frameKey - The unique key of the Animation Frame within the Animation.
2034
*/
21-
module.exports = 'stop';
35+
module.exports = 'animationstop';

src/animations/events/ANIMATION_UPDATE_EVENT.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,33 @@
77
/**
88
* The Animation Update Event.
99
*
10-
* This event is dispatched by an animation when it updates. This happens when the animation changes frame,
11-
* based on the animation frame rate and other factors like `timeScale` and `delay`.
10+
* This event is dispatched by a Sprite when an animation playing on it updates. This happens when the animation changes frame.
11+
* An animation will change frame based on the frme rate and other factors like `timeScale` and `delay`. It can also change
12+
* frame when stopped or restarted.
1213
*
13-
* Listen for it on the Animation using `anim.on('update', listener)`
14+
* Listen for it on the Sprite using `sprite.on('animationupdate', listener)`
15+
*
16+
* If an animation is playing faster than the game frame-rate can handle, it's entirely possible for it to emit several
17+
* update events in a single game frame, so please be aware of this in your code. The **final** event received that frame
18+
* is the one that is rendered to the game.
19+
*
20+
* The animation event flow is as follows:
21+
*
22+
* 1. `ANIMATION_START`
23+
* 2. `ANIMATION_UPDATE` (repeated for however many frames the animation has)
24+
* 3. `ANIMATION_REPEAT` (only if the animation is set to repeat, it then emits more update events after this)
25+
* 4. `ANIMATION_COMPLETE` (only if there is a finite, or zero, repeat count)
26+
*
27+
* If the animation is stopped directly, the `ANIMATION_STOP` event is dispatched instead of `ANIMATION_COMPLETE`.
28+
*
29+
* If the animation is restarted while it is already playing, `ANIMATION_RESTART` is emitted.
1430
*
1531
* @event Phaser.Animations.Events#ANIMATION_UPDATE
1632
* @since 3.50.0
1733
*
18-
* @param {Phaser.Animations.Animation} animation - A reference to the Animation that has updated on the Sprite.
34+
* @param {Phaser.Animations.Animation} animation - A reference to the Animation that has updated.
1935
* @param {Phaser.Animations.AnimationFrame} frame - The current Animation Frame of the Animation.
2036
* @param {Phaser.GameObjects.Sprite} gameObject - A reference to the Game Object on which the animation updated.
37+
* @param {string} frameKey - The unique key of the Animation Frame within the Animation.
2138
*/
22-
module.exports = 'update';
39+
module.exports = 'animationupdate';

src/animations/events/SPRITE_ANIMATION_COMPLETE_EVENT.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/animations/events/SPRITE_ANIMATION_KEY_COMPLETE_EVENT.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/animations/events/SPRITE_ANIMATION_KEY_REPEAT_EVENT.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/animations/events/SPRITE_ANIMATION_KEY_RESTART_EVENT.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)