Game Development Reference
In-Depth Information
Putting it all together
We will now begin to fill in the stub methods with some life. The game loop is a
good starting point; it is our driving engine that keeps the game world updated
and rendered in a continuous way. After this, we will add some sprites and verify
that the updating and rendering mechanism is working fine. In order to manipulate
the world and game objects, controls are added to receive and react on user input.
Finally, the
CameraHelper
class will be implemented to allow us to move around
freely in the game world and to select a game object of our choice that the camera is
supposed to follow.
The additions and modifications in code listings will be highlighted.
Building the game loop
The game loop will reside in the
CanyonBunnyMain
class'
render()
method. Before
we can add the new code, we have to import the following packages to gain access to
some classes that we are going to use:
import com.badlogic.gdx.Application;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
After this, add the following code to
create()
:
@Override
public void create () {
// Set Libgdx log level to DEBUG
Gdx.app.setLogLevel(Application.LOG_DEBUG);
// Initialize controller and renderer
worldController = new WorldController();
worldRenderer = new WorldRenderer(worldController);
}
First, we set the log level of LibGDX's built-in logger to debug the mode in order
to print out everything to the console that might be logged during runtime. Do not
forget to change the log level to something more appropriate such as
LOG_NONE
or
LOG_INFO
before publishing your game.
After this, we simply create a new instance of
WorldController
and
WorldRenderer
and save them in their respective member variables.