Game Development Reference
In-Depth Information
Finally, the animations are now ready to be used and queried for their frames that
should be currently displayed according to calculations. These calculations require
one input value, which is the so-called state time, as shown in the following code.
The state time is the elapsed time of an animation given in seconds. Usually, game
objects keep track of their animation time, as we will see shortly:
TextureRegion region = aniAll.getKeyFrame(stateTime);
Assuming that the stateTime in the preceding code line yields a value of 0 seconds,
the region variable will contain the first frame defined in the aniAll animation.
Animating the game screen
We are now going to animate the gold coin and bunny head game objects. However,
before we can start building new animations, some preparations need to take place
first, such as adding the actual image files to the project and rebuilding the texture
atlas afterwards.
Copy the following files to CanyonBunny-desktop/assets-raw/images/ :
anim_bunny_normal_XX.png (where XX is 01 , 02 , and 03 )
anim_bunny_copter_XX.png (where XX is 01 , 02 , 03 , 04 , and 05 )
anim_gold_coin_XX.png (where XX is 01 , 02 , 03 , 04 , 05 , and 06 )
Now, set the rebuildAtlas variable to true and run the Canyon Bunny desktop
application once to let the texture atlas be rebuilt with the newly added images for
our animations.
Defining and preparing new animations
The following screenshot depicts all the frames, including their indices of the
gold coin animation:
 
Search WWH ::




Custom Search