toyGraphics / com.anysolo.toyGraphics / Animation

Animation

class Animation

Animation is a set of pictures (activeFrames) showing in a sequence with given delay between them.

You create an animation from prepared AnimationFrames object passing it as frames parameter. One AnimationFrames object can be used to create as many animation as you want. Each animation cab use it own subset of frames in its own order.

To use an animation, you draw it using method "drawAnimation" of Graphics class. When you draw an animation you really draw the current frame of this animation. If the animation is stopped it does not have current frame and drawAnimation() draws nothing.

You have to call update() from AnimationManager object to update current frame in each animation.

"Delay" is how long, in milliseconds, you want one frame to be on the screen.

If you pass loop=true it is going to restart from the first frame after the last one. Without loop=true when the animation goes beyond the last frame it stops. drawAnimation() call for a stopped animation will be ignored.

Constructors

<init>

Animation(frames: AnimationFrames, activeFrames: List<Int>? = null, delay: Int = defaultFrameDelay, loop: Boolean = false)

Create an animation.

Properties

activeFrames

val activeFrames: List<Int>

delay

val delay: Int

How long you want to see one frame on the screen, in milliseconds.

frames

val frames: AnimationFrames

AnimationFrames object used as source of frames.

height

val height: Int

isRunning

val isRunning: Boolean

loop

val loop: Boolean

Do you want the animation to play in a loop?

manager

var manager: AnimationManager?

width

val width: Int

Functions

restart

fun restart(): Unit

Restart animation

start

fun start(manager: AnimationManager): Unit

Start the animation in given animation manager

stop

fun stop(): Unit

Stop the animation.

Companion Object Properties

defaultFrameDelay

const val defaultFrameDelay: Int

This frame delay will be used if you do not specify delay or pass null