Game Development Reference
In-Depth Information
regions = atlas.findRegions("anim_bunny_copter");
animCopterTransform = new Animation(1.0f / 10.0f, regions);
// Animation: Bunny Copter - unknot ears
regions = atlas.findRegions("anim_bunny_copter");
animCopterTransformBack = new Animation(1.0f / 10.0f, regions,
Animation.PlayMode.REVERSED);
// Animation: Bunny Copter - rotate ears
regions = new Array<AtlasRegion>();
regions.add(atlas.findRegion("anim_bunny_copter", 4));
regions.add(atlas.findRegion("anim_bunny_copter", 5));
animCopterRotate = new Animation(1.0f / 15.0f, regions);
}
}
With regards to the code for the gold coin animation, you may have stumbled
upon why we are inserting 10 additional copies of the animation's first frame at
the beginning. Well, actually we are cheating here a little bit to achieve an artificial
pause of the continuously looped animation that will now display the first frame for
a much longer period of time in comparison to the other ones. Unfortunately, there
is currently no way to define a per-frame duration and so we need to use a trick to
create a short pause after a full animation cycle that basically avoids too flashy gold
coins in our special case.
Animating the gold coin game object
Now, add the following import line to the AbstractGameObject class:
import com.badlogic.gdx.graphics.g2d.Animation;
Then, add the following lines of code to the same class:
public float stateTime;
public Animation animation;
public void setAnimation (Animation animation) {
this.animation = animation;
stateTime = 0;
}
 
Search WWH ::




Custom Search