Animation

From Slick2D Wiki
Jump to: navigation, search

Animations are a collection of images being displayed one after another, each image (or frame) for a set amount of time. Slick provides a class to allow you to build animation that can be reused by the entities in your game.

The Animation class allows you to add images with given durations and build an animation. By default the animation will automatically update between calls to its render() method. However, this isn't always useful since there may be a great deal of time between calls to the method (for instance you might only render aliens while they're on the screen). In these cases it's advisable to turn off the auto update (a parameter to the constructor) and call the update method of the animation directly from the update method of your game.

Animations can be stopped, started and restarted (returning to the first frame of the animation). In addition Animations can be placed in “ping pong” mode which will cause them to oscillate backwards and forwards across the frames.