Game Development Reference
In-Depth Information
Next, we will implement two new screen classes. Create a new file for the
MenuScreen class and add the following code:
package com.packtpub.libgdx.canyonbunny.screens;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
public class MenuScreen extends AbstractGameScreen {
private static final String TAG = MenuScreen.class.getName();
public MenuScreen (Game game) {
super(game);
}
@Override
public void render (float deltaTime) {
Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
if(Gdx.input.isTouched())
game.setScreen(new GameScreen(game));
}
@Override public void resize (int width, int height) { }
@Override public void show () { }
@Override public void hide () { }
@Override public void pause () { }
}
This is still a very rough implementation of the menu screen, but it will serve us well
for the moment. The render() method takes care of only two things. It constantly
clears the screen by filling it with a solid black color and checks whether the screen
has been touched, which also includes mouse clicks if the game is running on a
desktop. As soon as a touch has been detected, the screen will be switched from the
menu screen to the game screen that shows our actual game world.
Next, create a new file for the GameScreen class and add the following code:
package com.packtpub.libgdx.canyonbunny.screens;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
 
Search WWH ::




Custom Search