Skip to content

Commit b285b2b

Browse files
committed
Expose manager functions. Fix phaserjs#5345
1 parent 00b8bb4 commit b285b2b

1 file changed

Lines changed: 93 additions & 0 deletions

File tree

src/animations/AnimationState.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,99 @@ var AnimationState = new Class({
17011701
return anim;
17021702
},
17031703

1704+
/**
1705+
* Generate an array of {@link Phaser.Types.Animations.AnimationFrame} objects from a texture key and configuration object.
1706+
*
1707+
* Generates objects with string based frame names, as configured by the given {@link Phaser.Types.Animations.GenerateFrameNames}.
1708+
*
1709+
* It's a helper method, designed to make it easier for you to extract all of the frame names from texture atlases.
1710+
* If you're working with a sprite sheet, see the `generateFrameNumbers` method instead.
1711+
*
1712+
* Example:
1713+
*
1714+
* If you have a texture atlases loaded called `gems` and it contains 6 frames called `ruby_0001`, `ruby_0002`, and so on,
1715+
* then you can call this method using: `this.anims.generateFrameNames('gems', { prefix: 'ruby_', end: 6, zeroPad: 4 })`.
1716+
*
1717+
* The `end` value tells it to look for 6 frames, incrementally numbered, all starting with the prefix `ruby_`. The `zeroPad`
1718+
* value tells it how many zeroes pad out the numbers. To create an animation using this method, you can do:
1719+
*
1720+
* ```javascript
1721+
* this.anims.create({
1722+
* key: 'ruby',
1723+
* repeat: -1,
1724+
* frames: this.anims.generateFrameNames('gems', {
1725+
* prefix: 'ruby_',
1726+
* end: 6,
1727+
* zeroPad: 4
1728+
* })
1729+
* });
1730+
* ```
1731+
*
1732+
* Please see the animation examples for further details.
1733+
*
1734+
* @method Phaser.Animations.AnimationState#generateFrameNames
1735+
* @since 3.50.0
1736+
*
1737+
* @param {string} key - The key for the texture containing the animation frames.
1738+
* @param {Phaser.Types.Animations.GenerateFrameNames} [config] - The configuration object for the animation frame names.
1739+
*
1740+
* @return {Phaser.Types.Animations.AnimationFrame[]} The array of {@link Phaser.Types.Animations.AnimationFrame} objects.
1741+
*/
1742+
generateFrameNames: function (key, config)
1743+
{
1744+
return this.animationManager.generateFrameNames(key, config);
1745+
},
1746+
1747+
/**
1748+
* Generate an array of {@link Phaser.Types.Animations.AnimationFrame} objects from a texture key and configuration object.
1749+
*
1750+
* Generates objects with numbered frame names, as configured by the given {@link Phaser.Types.Animations.GenerateFrameNumbers}.
1751+
*
1752+
* If you're working with a texture atlas, see the `generateFrameNames` method instead.
1753+
*
1754+
* It's a helper method, designed to make it easier for you to extract frames from sprite sheets.
1755+
* If you're working with a texture atlas, see the `generateFrameNames` method instead.
1756+
*
1757+
* Example:
1758+
*
1759+
* If you have a sprite sheet loaded called `explosion` and it contains 12 frames, then you can call this method using:
1760+
* `this.anims.generateFrameNumbers('explosion', { start: 0, end: 12 })`.
1761+
*
1762+
* The `end` value tells it to stop after 12 frames. To create an animation using this method, you can do:
1763+
*
1764+
* ```javascript
1765+
* this.anims.create({
1766+
* key: 'boom',
1767+
* frames: this.anims.generateFrameNames('explosion', {
1768+
* start: 0,
1769+
* end: 12
1770+
* })
1771+
* });
1772+
* ```
1773+
*
1774+
* Note that `start` is optional and you don't need to include it if the animation starts from frame 0.
1775+
*
1776+
* To specify an animation in reverse, swap the `start` and `end` values.
1777+
*
1778+
* If the frames are not sequential, you may pass an array of frame numbers instead, for example:
1779+
*
1780+
* `this.anims.generateFrameNumbers('explosion', { frames: [ 0, 1, 2, 1, 2, 3, 4, 0, 1, 2 ] })`
1781+
*
1782+
* Please see the animation examples and `GenerateFrameNumbers` config docs for further details.
1783+
*
1784+
* @method Phaser.Animations.AnimationState#generateFrameNumbers
1785+
* @since 3.50.0
1786+
*
1787+
* @param {string} key - The key for the texture containing the animation frames.
1788+
* @param {Phaser.Types.Animations.GenerateFrameNumbers} config - The configuration object for the animation frames.
1789+
*
1790+
* @return {Phaser.Types.Animations.AnimationFrame[]} The array of {@link Phaser.Types.Animations.AnimationFrame} objects.
1791+
*/
1792+
generateFrameNumbers: function (key, config)
1793+
{
1794+
return this.animationManager.generateFrameNumbers(key, config);
1795+
},
1796+
17041797
/**
17051798
* Removes a locally created Animation from this Sprite, based on the given key.
17061799
*

0 commit comments

Comments
 (0)