Book Image

LibGDX Game Development By Example

By : James Cook
Book Image

LibGDX Game Development By Example

By: James Cook

Overview of this book

Table of Contents (18 chapters)
LibGDX Game Development By Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Introducing Pete


So far we have created a level using Tiled, and we have implemented tile maps in LibGDX so that we can see that level. The next step is to introduce our characters into this world and have them interact with the surroundings.

The preceding image shows Pete, our lovely squirrel! He has four different poses, two for walking and one each for jumping up and down.

Adding our character

Before we add our textures to Pete, let's go through the process of creating our character in code and have them interact with the world, then we can implement the animations.

Let's create class for Pete, I have called it Pete and in that class we are going create the core components for controlling Pete, and also add a basic collision rectangle. This class is also going to be very similar to the Flappee class from the previous chapters.

Here is how the Pete class should look:

public class Pete {
  private static final float MAX_X_SPEED = 2;
  private static final float MAX_Y_SPEED = 2;
  public static...