Constructor

new(Sprite:FlxSprite)

Variables

curAnim:FlxAnimation

Property access for currently playing animation (warning: can be null).

finished:Bool

Whether the current animation has finished playing.

frameIndex:Int = -1

The frame index of the current animation. Can be changed manually.

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!

name:String

Gets or sets the currently playing animation (warning: can be null).

paused:Bool

Pause or resume the current animation.

callback:String‑>Int‑>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: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:Int = 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. "run").

Frames

An array of indices indicating what frames to play in what order (e.g. [0, 1, 2]).

FrameRate

The speed in frames per second that the animation should play at (e.g. 40 fps).

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:Int = 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. "run").

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. [0, 1, 2]).

Postfix

Common ending of image names in the atlas (e.g. ".png").

FrameRate

The speed in frames per second that the animation should play at (e.g. 40 fps).

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:Int = 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. "run").

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. 40 fps).

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:Int = 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. "run").

Prefix

Common beginning of image names in atlas (e.g. "tiles-").

FrameRate

The speed in frames per second that the animation should play at (e.g. 40 fps).

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:Int = 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. "run").

Prefix

Common beginning of image names in the atlas (e.g. "tiles-").

Indices

An array of strings indicating what frames to play in what order (e.g. ["01", "02", "03"]).

Postfix

Common ending of image names in atlas (e.g. ".png").

FrameRate

The speed in frames per second that the animation should play at (e.g. 40 fps).

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. "run").

Frames

An array of indices indicating what frames to append (e.g. [0, 1, 2]).

appendByIndices(Name:String, Prefix:String, Indices:Array<Int>, Postfix: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. "run").

Prefix

Common beginning of image names in atlas (e.g. "tiles-").

Indices

An array of numbers indicating what frames to append (e.g. [0, 1, 2]).

Postfix

Common ending of image names in atlas (e.g. ".png").

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. "run").

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. "run").

Prefix

Common beginning of image names in atlas (e.g. "tiles-")

appendByStringIndices(Name:String, Prefix:String, Indices:Array<String>, Postfix: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. "run").

Prefix

Common beginning of image names in the atlas (e.g. "tiles-").

Indices

An array of strings indicating what frames to append (e.g. ["01", "02", "03"]).

Postfix

Common ending of image names in atlas (e.g. ".png").

finish():Void

Stops current animation and sets its frame to the last one.

inlinegetByName(Name:String):FlxAnimation

Gets the FlxAnimation object with the specified name.

inlinegetFrameIndex(Frame:FlxFrame):Int

Helper function used for finding index of FlxFrame in _framesData's frames array

Parameters:

Frame

FlxFrame to find

Returns:

position of specified FlxFrame object.

inlinepause():Void

Pauses the current animation.

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.

inlinereset():Void

Stops current animation and resets its frame index to zero.

inlineresume():Void

Resumes the current animation if it exists.

inlinereverse():Void

Reverses current animation if it exists.

stop():Void

Just stops current animation.

update(elapsed:Float):Void