Game Development Reference
In-Depth Information
public
MySuperAwesomeStartScreen(Game game) {
super
(game);
awesomePic = game.getGraphics().newPixmap("data/pic.png",
PixmapFormat.
RGB565
);
}
@Override
public void
update(
float
deltaTime) {
x += 1;
if
(x > 100)
x = 0;
}
@Override
public void
present(
float
deltaTime) {
game.getGraphics().clear(0);
game.getGraphics().drawPixmap(awesomePic, x, 0, 0, 0,
awesomePic.getWidth(), awesomePic.getHeight());
}
@Override
public void
pause() {
// nothing to do here
}
@Override
public void
resume() {
// nothing to do here
}
@Override
public void
dispose() {
awesomePic.dispose();
}
}
Let's see what this class, in combination with the
MySuperAwesomeGame
class, will do:
1.
When the
MySuperAwesomeGame
class is created, it will set up the
window, the UI component to which we render and from which we
receive events, the callbacks to receive window and input events,
and the main loop thread. Finally, it will call its own
MySuperAwesomeGame.getStartScreen()
method, which will return an
instance of the
MySuperAwesomeStartScreen()
class.
2.
In the
MySuperAwesomeStartScreen
constructor, we load a bitmap from
disk and store it in a member variable. This completes our screen setup,
and the control is handed back to the
MySuperAwesomeGame
class.
3.
The main loop thread will now constantly call the
MySuperAwesomeStartScreen.update()
and
MySuperAwesomeStartScreen
.present()
methods of the instance we just created.