O'Reilly logo

LibGDX Cross-Platform Development Blueprints by Indraneel Potnis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Animating the mole

We will see how to animate our mole in this section.

Jumping up and down

We will animate the mole such that it comes out of the hole and goes back in again. This process continues repeatedly. Let's define some variables in our Mole class:

public enum State {GOINGUP,GOINGDOWN}; // define mole's states
public State state=State.GOINGUP;  // variable describing mole's current state
public float currentHeight = 0.0f; // current height of the mole above ground
public float speed =2f; // speed of the mole as it goes up and down

We have defined two states for the mole. One for going up and the other for going down. The state variable is used to hold the current value of the state. This is initialized to go up. The currentHeight variable ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required