Game Development Reference
In-Depth Information
Let's assume that the waterfall animation is now available in the texture atlas
( atlas.pack ). To retrieve any given image from a texture atlas, we already know
that we can simply call the findRegion() method and pass in the original filename
without its extension to reference it. The preceding code example shows that you
can also do this with an animation to get the first frame, or you can pass a second
argument to specify a concrete frame index like index number 3 to get the third frame.
The next line uses the findRegions() method instead of findRegion() . Notice the
plural s in the method's name. This method returns a whole array of frames associated
with the supplied name which is stored in the allFrames variable for now.
The following lines of code show how new animations are built using the
Animation class:
float fps = 1.0f / 15.0f; // Time between frames in seconds
Animation aniFirst, aniFirstThird, aniAll, aniAllPingpong;
aniFirst = new Animation(fps, firstFrame);
aniFirstThird = new Animation(fps, firstFrame, thirdFrame);
aniAll = new Animation(fps, allFrames);
aniAllPingPong = new Animation(fps, allFrames,
Animation.PlayMode.LOOP_PINGPONG);
The constructor of the class takes the time given in seconds that describes the time
stepping or delay between the current and the next frame that is to be displayed. In
this example, we use a frame rate of 15 frames per second. As the example code shows
us further, we can pass in either an arbitrary number of AtlasRegion objects (our
individual frames) or an array of those objects to define what frames should be used
and in what particular order. Another feature of the Animation class is its play mode.
Choosing between animation play modes
There are six distinct play modes we can choose from. They are as follows:
NORMAL : This plays the animation once (first frame to last)
REVERSED : This plays the animation once (last frame to first)
LOOP : This plays the animation in a loop (first frame to last)
LOOP_REVERSED : This plays the animation in a loop (last frame to first)
LOOP_PINGPONG : This plays the animation in a loop (first frame, to last,
to first)
LOOP_RANDOM : This plays the animation in a loop (random frames)
The NORMAL play mode is used as default if it is not explicitly set in the code.
 
Search WWH ::




Custom Search