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

Adding textures and animations


We now have our assets. Let's add them to the assets folder in our project and start adding them into the game.

First up, let's add the background (bg.png). This is a relatively simple affair; like we did earlier, we create a Texture object that represents the background, then draw it. So, in the GameScreen class, add the following code:

private Texture background;

public void show() {
  /** Code omitted for brevity **/
  background = new Texture(Gdx.files.internal("bg.png"));
}

private void draw() {
  batch.setProjectionMatrix(camera.projection);
  batch.setTransformMatrix(camera.view);
  batch.begin();
  batch.draw(background, 0, 0);
  drawScore();
  batch.end();
}

Let's run it and see how it looks:

Excellent, we are almost there! OK, let's not kid ourselves, we still have more to do.

Next, let's bring those flowers to life.

First up, let's modify our Flower class to take two Texture objects, which will represent the top and bottom flowers. So, add the following...