Game Development Reference
In-Depth Information
stage.dispose();
skinCanyonBunny.dispose();
}
@Override
public void show () {
stage = new Stage(new StretchViewport(Constants.VIEWPORT_GUI_WIDTH,
Constants.VIEWPORT_GUI_HEIGHT));
Gdx.input.setInputProcessor(stage);
rebuildStage();
}
The
show()
method is called when the screen is shown. It initializes the stage, sets
it as LibGDX's current input processor so that the stage will receive all the future
inputs, and finally, the stage is rebuilt by calling
rebuildStage()
. The
hide()
method will free the allocated resources when the screen is hidden. The
resize()
method sets the viewport size of the stage.
Lastly, make the following changes to the
render()
method in the same class:
@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 (debugEnabled) {
debugRebuildStage -= deltaTime;
if (debugRebuildStage <= 0) {
debugRebuildStage = DEBUG_REBUILD_INTERVAL;
rebuildStage();
}
}
stage.act(deltaTime);
stage.draw();
Table.drawDebug(stage);
}
The code in
render()
that would switch to the game screen when the screen is
touched was replaced by calls to update and render the stage. The statement
Table.
drawDebug()
is a debugging feature of
TableLayout
, which enables you to draw
debug visuals in a scene. Additionally, you need to specify which
Table
widgets
should draw debug lines by calling their
debug()
method.