Constructor
Variables
frameName:String
Tell the sprite to change to a frame with specific name. Useful for sprites with loaded TexturePacker atlas.
read onlyframes:Int
The total number of frames in this image. WARNING: assumes each row in the sprite sheet is full!
read onlynumFrames:Int
The total number of frames in this image. WARNING: assumes each row in the sprite sheet is full!
5.3.0
.callback:(name:String, frameNumber:Int, frameIndex:Int) ‑> Void
If assigned, will be called each time the current animation's frame changes. A function that has 3 parameters: a string name, a frame number, and a frame index.
finishCallback:(name:String) ‑> Void
If assigned, will be called each time the current animation finishes. A function that has 1 parameter: a string name - animation name.
Methods
add(name:String, frames:Array<Int>, frameRate:Float = 30.0, looped:Bool = true, flipX:Bool = false, flipY:Bool = false):Void
Adds a new animation to the sprite.
Parameters:
name | What this animation should be called (e.g. |
---|---|
frames | An array of indices indicating what frames to play in what order (e.g. |
frameRate | The speed in frames per second that the animation should play at (e.g. |
looped | Whether or not the animation is looped or just plays once. |
flipX | Whether the frames should be flipped horizontally. |
flipY | Whether the frames should be flipped vertically. |
addByIndices(Name:String, Prefix:String, Indices:Array<Int>, Postfix:String, FrameRate:Float = 30, Looped:Bool = true, FlipX:Bool = false, FlipY:Bool = false):Void
Adds a new animation to the sprite.
Parameters:
Name | What this animation should be called (e.g. |
---|---|
Prefix | Common beginning of image names in the atlas (e.g. "tiles-"). |
Indices | An array of numbers indicating what frames to play in what order (e.g. |
Postfix | Common ending of image names in the atlas (e.g. |
FrameRate | The speed in frames per second that the animation should play at (e.g. |
Looped | Whether or not the animation is looped or just plays once. |
FlipX | Whether the frames should be flipped horizontally. |
FlipY | Whether the frames should be flipped vertically. |
addByNames(Name:String, FrameNames:Array<String>, FrameRate:Float = 30, Looped:Bool = true, FlipX:Bool = false, FlipY:Bool = false):Void
Adds a new animation to the sprite.
Parameters:
Name | What this animation should be called (e.g. |
---|---|
FrameNames | An array of image names from the atlas indicating what frames to play in what order. |
FrameRate | The speed in frames per second that the animation should play at (e.g. |
Looped | Whether or not the animation is looped or just plays once. |
FlipX | Whether the frames should be flipped horizontally. |
FlipY | Whether the frames should be flipped vertically. |
addByPrefix(name:String, prefix:String, frameRate:Float = 30.0, looped:Bool = true, flipX:Bool = false, flipY:Bool = false):Void
Adds a new animation to the sprite.
Parameters:
name | What this animation should be called (e.g. |
---|---|
prefix | Common beginning of image names in atlas (e.g. |
frameRate | The animation speed in frames per second. Note: individual frames have their own duration, which overrides this value. |
looped | Whether or not the animation is looped or just plays once. |
flipX | Whether the frames should be flipped horizontally. |
flipY | Whether the frames should be flipped vertically. |
addByStringIndices(Name:String, Prefix:String, Indices:Array<String>, Postfix:String, FrameRate:Float = 30, Looped:Bool = true, FlipX:Bool = false, FlipY:Bool = false):Void
Adds a new animation to the sprite. Should be slightly faster than addByIndices()
.
Parameters:
Name | What this animation should be called (e.g. |
---|---|
Prefix | Common beginning of image names in the atlas (e.g. |
Indices | An array of strings indicating what frames to play in what order
(e.g. |
Postfix | Common ending of image names in atlas (e.g. |
FrameRate | The speed in frames per second that the animation should play at (e.g. |
Looped | Whether or not the animation is looped or just plays once. |
FlipX | Whether the frames should be flipped horizontally. |
FlipY | Whether the frames should be flipped vertically. |
append(name:String, frames:Array<Int>):Void
Adds to an existing animation in the sprite by appending the specified frames to the existing frames. Use this method when the indices of the frames in the atlas are already known. The animation must already exist in order to append frames to it.
Parameters:
name | What the existing animation is called (e.g. |
---|---|
frames | An array of indices indicating what frames to append (e.g. |
appendByIndices(name:String, prefix:String, indices:Array<Int>, suffix:String):Void
Adds to an existing animation in the sprite by appending the specified frames to the existing frames.
Use this method when the names of each frame from the atlas share a common prefix
and postfix (e.g. "walk00.png"
, "walk01.png"
).
Leading zeroes are ignored for matching indices (5
will match "5"
and "005"
).
The animation must already exist in order to append frames to it.
Parameters:
name | What the existing animation is called (e.g. |
---|---|
prefix | Common beginning of image names in atlas (e.g. |
indices | An array of numbers indicating what frames to append (e.g. |
suffix | Common ending of image names in atlas (e.g. |
appendByNames(name:String, frameNames:Array<String>):Void
Adds to an existing animation in the sprite by appending the specified frames to the existing frames.
Use this method when the exact name of each frame from the atlas is known (e.g. "walk00.png"
, "walk01.png"
).
The animation must already exist in order to append frames to it.
Parameters:
Name | What the existing animation is called (e.g. |
---|---|
FrameNames | An array of image names from atlas indicating what frames to append. |
appendByPrefix(name:String, prefix:String):Void
Adds to an existing animation in the sprite by appending the specified frames to the existing frames.
Use this method when the names of each frame from the atlas share a common prefix
(e.g. "walk00.png"
, "walk01.png"
).
Frames are sorted numerically while ignoring postfixes (e.g. ".png"
, ".gif"
).
The animation must already exist in order to append frames to it.
Parameters:
name | What the existing animation is called (e.g. |
---|---|
prefix | Common beginning of image names in atlas (e.g. |
appendByStringIndices(name:String, prefix:String, indices:Array<String>, suffix:String):Void
Adds to an existing animation in the sprite by appending the specified frames to the existing frames.
Should be slightly faster than appendByIndices()
. Use this method when the names of each frame from
the atlas share a common prefix and postfix (e.g. "walk00.png"
, "walk01.png"
).
The animation must already exist in order to append frames to it. FrameRate and Looped are unchanged.
Parameters:
name | What the existing animation is called (e.g. |
---|---|
prefix | Common beginning of image names in the atlas (e.g. |
indices | An array of strings indicating what frames to append (e.g. |
suffix | Common ending of image names in atlas (e.g. |
exists(name:String):Bool
Checks if an animation exists by it's name.
Parameters:
name | The animation name. |
---|
4.11.0
.getAnimationList():Array<FlxAnimation>
Gets a list with all the animations that are added in a sprite.
WARNING: Do not confuse with getNameList
, this function returns the animation instances
Returns:
an array with all the animations.
4.11.0
.inlinegetFrameIndex(frame:FlxFrame):Int
getNameList():Array<String>
Gets a list with all the name animations that are added in a sprite
WARNING: Do not confuse with getAnimationList
, this function returns the animation names
Returns:
an array with all the animation names in it.
4.11.0
.play(animName:String, force:Bool = false, reversed:Bool = false, frame:Int = 0):Void
Plays an existing animation (e.g. "run"
).
If you call an animation that is already playing, it will be ignored.
Parameters:
animName | The string name of the animation you want to play. |
---|---|
force | Whether to force the animation to restart. |
reversed | Whether to play animation backwards or not. |
frame | The frame number in the animation you want to start from. If a negative value is passed, a random frame is used. |
randomFrame():Void
Changes to a random animation frame. Useful for instantiating particles or other weird things.
remove(Name:String):Void
Removes (and destroys) an animation.
Parameters:
Name | The name of animation to remove. |
---|