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.

@:value(-1)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

Deprecated: "frames is deprecated, use numFrames"

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

read onlynumFrames:Int

The total number of frames in this image. WARNING: assumes each row in the sprite sheet is full!

Available since

5.3.0

.

paused:Bool

Pause or resume the current animation.

@:value(1.0)timeScale:Float = 1.0

How fast or slow time should pass for this animation controller

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

@:value({ flipY : false, flipX : false, looped : true, frameRate : 30.0 })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. "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.

@:value({ FlipY : false, FlipX : false, Looped : true, FrameRate : 30 })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. "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.

@:value({ FlipY : false, FlipX : false, Looped : true, FrameRate : 30 })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. "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.

@:value({ flipY : false, flipX : false, looped : true, frameRate : 30.0 })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. "run").

prefix

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

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.

@:value({ FlipY : false, FlipX : false, Looped : true, FrameRate : 30 })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. "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>, 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. "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]).

suffix

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>, 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. "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"]).

suffix

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

exists(name:String):Bool

Checks if an animation exists by it's name.

Parameters:

name

The animation name.

Available since

4.11.0

.

finish():Void

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

@:has_untypedgetAnimationList():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.

Available since

4.11.0

.

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.

@:has_untypedgetNameList():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.

Available since

4.11.0

.

inlinepause():Void

Pauses the current animation.

@:value({ frame : 0, reversed : false, force : false })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.

rename(oldName:String, newName:String):Void

Renames the animation with a new name.

Parameters:

oldName

the name that is replaced.

newName

the name that replaces the old one.

Available since

4.11.0

.

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