Game Development Reference
In-Depth Information
private boolean
inBounds(TouchEvent event,
int
x,
int
y,
int
width,
int
height) {
if
(event.x > x && event.x < x + width - 1 &&
event.y > y && event.y < y + height - 1)
return true
;
else
return false
;
}
The
inBounds()
method works as previously discussed: put in a
TouchEvent
and a rectangle, and
it tells you whether the touch event's coordinates are inside that rectangle.
public void
present(
float
deltaTime) {
Graphics g = game.getGraphics();
g.drawPixmap(Assets.
background
, 0, 0);
g.drawPixmap(Assets.
logo
, 32, 20);
g.drawPixmap(Assets.
mainMenu
, 64, 220);
if
(Settings.
soundEnabled
)
g.drawPixmap(Assets.
buttons
, 0, 416, 0, 0, 64, 64);
else
g.drawPixmap(Assets.
buttons
, 0, 416, 64, 0, 64, 64);
}
The
present()
method is probably the one you've been waiting for most, but it isn't all that
exciting. Our little game framework makes it really simple to render our main menu screen. All
we do is render the background at (0,0), which will basically erase our framebuffer, so no call to
Graphics.clear()
is needed. Next, we draw the logo and main menu entries at the coordinates
shown in Figure
6-2
. We end that method by drawing the sound toggle button based on the
current setting. As you can see, we use the same
Pixmap
, but only draw the appropriate portion
of it (the sound toggle button; see Figure
6-1
). Now that was easy.
public void
pause() {
Settings.
save
(game.getFileIO());
}
The final piece we need to discuss is the
pause()
method. Since we can change one of the
settings on that screen, we have to make sure that it gets persisted to the external storage. With
our
Settings
class, that's pretty easy too!
public void
resume() {
}
public void
dispose() {
}
}
The
resume()
and
dispose()
methods don't have anything to do in this
Screen
.