Game Development Reference
In-Depth Information
To continuously update and render the game world to the screen, add the following
code to render() :
@Override
public void render() {
// Update game world by the time that has passed
// since last rendered frame.
worldController.update(Gdx.graphics.getDeltaTime());
// Sets the clear screen color to: Cornflower Blue
Gdx.gl.glClearColor(0x64/255.0f, 0x95/255.0f, 0xed/255.0f,
0xff/255.0f);
// Clears the screen
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
// Render game world to screen
worldRenderer.render();
}
The game world is incrementally updated using delta times. Luckily, LibGDX already
does the math and housekeeping behind this for us, so all we need to do is to query the
value by calling getDeltaTime() from the Gdx.graphics module and passing it to
update() of WorldController . After this, LibGDX is instructed to execute two direct
OpenGL calls using the Gdx.gl module. The first call glClearColor() sets the color
white to a light blue color using red, green, blue, and alpha ( RGBA ) values written
in a hexadecimal notation. Each color component needs to be expressed as a floating-
point value ranging between 0 and 1 with a resolution of 8 bits. This is the reason why
we are also dividing each color component by the value of 255.0f (8 bit = 2 8 = 256 =
0..255 distinct levels per color component).
Some prefer a hexadecimal notation, while others prefer a decimal
notation. Here is an example of setting the same color in a decimal
notation if you prefer to do so:
Gdx.gl.glClearColor(
100/255.0f, 149/255.0f, 237/255.0f, 255/255.0f);
The second call glClear() uses the color white we set before to fill in the screen, and
therefore erase all of the screen's previous contents. The last step renders the new
frame of the updated game world to the screen.
 
Search WWH ::




Custom Search