Fork me on GitHub
View source

package 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) : Void

Constructor.


Parameters:
source   

Source image.

frameWidth   

Frame width.

frameHeight   

Frame height.

Variables

complete : Bool

If the animation has stopped.

read only currentAnimation : Maybe<Animation>

The currently playing animation.

frame : Int

Sets the current frame index.

index : Int

Current index of the playing animation.

onAnimationComplete : Signal1<Animation>

Callback function for animation end.

rate : Float

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

reverse : Bool

If the animation is played in reverse.

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

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:

Animation 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

stop (reset : Bool = false) : Void

Immediately stops the currently playing animation.


Parameters:
reset   

If true, resets the animation to the first frame.