Fork me on GitHub
View source

package com.haxepunk.graphics

class Spritemap


extends Image
extended by TiledSpritemap

Performance-optimized animated Image. Can have multiple animations, which draw frames from the provided source image to the screen.

Constructor

View source

new (source : TileType, frameWidth : Int = 0, frameHeight : Int = 0, cbFunc : Void ->Void, ) : Void

Constructor.


Parameters:
source   

Source image.

frameWidth   

Frame width.

frameHeight   

Frame height.

cbFunc   

Optional callback function for animation end.

Variables

read only columns : Int

Columns in the Spritemap.

complete : Bool

If the animation has stopped.

read only currentAnim : String

The currently playing animation.

frame : Int

Sets the current frame index. When you set this, any animations playing will be stopped to force the frame.

read only frameCount : Int

The amount of frames in the Spritemap.

index : Int

Current index of the playing animation.

rate : Float

Animation speed factor, alter this to speed up/slow down all animations.

reverse : Bool

If the animation is played in reverse.

read only rows : Int

Rows in the Spritemap.

Functions

View source

add (name : String, frames : Array<Int>, frameRate : Float = 0, loop : Bool = true) : Animation

Add an Animation.


Parameters:
name   

Name of the animation.

frames   

Array of frame indices to animate through.

frameRate   

Animation speed (in frames per second, 0 defaults to assigned frame rate)

loop   

If the animation should loop


Returns:

A new Anim object for the animation.

View source

getFrame (column : Int = 0, row : Int = 0) : Int

Gets the frame index based on the column and row of the source image.


Parameters:
column   

Frame column.

row   

Frame row.


Returns:

Frame index.

View source

play (name : String = "", reset : Bool = false, reverse : Bool = false) : Animation

Plays an animation previous defined by add().


Parameters:
name   

Name of the animation to play.

reset   

If the animation should force-restart if it is already playing.

reverse   

If the animation should be played backward.


Returns:

Anim object representing the played animation.

View source

playAnimation (anim : Animation, reset : Bool = false, reverse : Bool = false) : Animation

Plays or restarts the supplied Animation.


Parameters:
animation   

The Animation object to play

reset   

When the supplied animation is currently playing, should it be force-restarted

reverse   

If the animation should be played backward.


Returns:

Anim object representing the played animation.

View source

playFrames (frames : Array<Int>, frameRate : Float = 0, loop : Bool = true, reset : Bool = false, reverse : Bool = false) : Animation

Plays a new ad hoc animation.


Parameters:
frames   

Array of frame indices to animate through.

frameRate   

Animation speed (in frames per second, 0 defaults to assigned frame rate)

loop   

If the animation should loop

reset   

When the supplied frames are currently playing, should the animation be force-restarted

reverse   

If the animation should be played backward.


Returns:

Anim object representing the played animation.

View source

randFrame () : Void

Assigns the Spritemap to a random frame.

View source

restart () : Void

Resets the animation to play from the beginning.

View source

setAnimFrame (name : String, index : Int) : Void

Sets the frame to the frame index of an animation.


Parameters:
name   

Animation to draw the frame frame.

index   

Index of the frame of the animation to set to.

View source

setFrame (column : Int = 0, row : Int = 0) : Void

Sets the current display frame based on the column and row of the source image. When you set the frame, any animations playing will be stopped to force the frame.


Parameters:
column   

Frame column.

row   

Frame row.

View source

stop (reset : Bool = false) : Void

Immediately stops the currently playing animation.


Parameters:
reset   

If true, resets the animation to the first frame.