Game Development Reference
In-Depth Information
Now, add the following import line to the BunnyHead class:
import com.badlogic.gdx.graphics.g2d.Animation;
Then, add the following lines of code to the same class:
private Animation animNormal;
private Animation animCopterTransform;
private Animation animCopterTransformBack;
private Animation animCopterRotate;
After this, make the following changes to the same class:
public void init () {
dimension.set(1, 1);
animNormal = Assets.instance.bunny.animNormal;
animCopterTransform = Assets.instance.bunny.animCopterTransform;
animCopterTransformBack =
Assets.instance.bunny.animCopterTransformBack;
animCopterRotate = Assets.instance.bunny.animCopterRotate;
setAnimation(animNormal);
// Center image on game object
origin.set(dimension.x / 2, dimension.y / 2);
...
}
In the init() method, we store the references of every animation we are going to
use in the corresponding local variables for much shorter names. Moreover, the
starting animation is set to animNormal .
Now, make the following changes to the same class:
@Override
public void update (float deltaTime) {
super.update(deltaTime);
if (velocity.x != 0) {
viewDirection = velocity.x < 0 ? VIEW_DIRECTION.LEFT
: VIEW_DIRECTION.RIGHT;
}
if (timeLeftFeatherPowerup > 0) {
if (animation == animCopterTransformBack) {
// Restart "Transform" animation if another feather power-up
 
Search WWH ::




Custom Search