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

Adding some color

This topic will include how to add the background and the hole sprites for the mole to come up and down.

Adding the background

Let's quickly add a background to our game. In the GameManager class, we will add these variables:

static Texture backgroundTexture; // texture image for background
static Sprite backgroundSprite;   // sprite for background

In the GameManager class' initialize() method, we load the texture and initialize the sprite to cover the whole screen:

backgroundTexture = new Texture(Gdx.files.internal("data/ground.jpg")); backgroundSprite = new Sprite(backgroundTexture); //set background sprite // set background sprite's dimensions and position backgroundSprite.setSize(width, height); backgroundSprite.setPosition(0,0f); ...

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