Game Development Reference
In-Depth Information
guiCam.touchToWorld(touchPoint.set(event.x, event.y));
if
(OverlapTester.
pointInRectangle
(playBounds, touchPoint)) {
Assets.
playSound
(Assets.
clickSound
);
game.setScreen(
new
GameScreen(game));
}
if
(OverlapTester.
pointInRectangle
(settingsBounds, touchPoint)) {
Assets.
playSound
(Assets.
clickSound
);
game.setScreen(
new
SettingsScreen(game));
}
}
}
In the
update()
method, we fetch the touch events and check for “touch-up� events. If there is
such an event, we transform its real coordinates to the coordinate system the camera sets up.
All that's left to do is to check the touch point against the two rectangles bounding the menu
entries. If one of them is hit, we play the click sound and transition to the respective screen.
@Override
public void
present(
float
deltaTime) {
GL10 gl = glGraphics.getGL();
gl.glClear(GL10.
GL_COLOR_BUFFER_BIT
);
guiCam.setViewportAndMatrices();
gl.glEnable(GL10.
GL_TEXTURE_2D
);
batcher.beginBatch(Assets.
background
);
batcher.drawSprite(240, 160, 480, 320, Assets.
backgroundRegion
);
batcher.endBatch();
gl.glEnable(GL10.
GL_BLEND
);
gl.glBlendFunc(GL10.
GL_SRC_ALPHA
, GL10.
GL_ONE_MINUS_SRC_ALPHA
);
batcher.beginBatch(Assets.
items
);
batcher.drawSprite(240, 240, 384, 128, Assets.
logoRegion
);
batcher.drawSprite(240, 100, 224, 64, Assets.
menuRegion
);
batcher.endBatch();
gl.glDisable(GL10.
GL_BLEND
);
gl.glDisable(GL10.
GL_TEXTURE_2D
);
}
The
present()
method does the same thing it did in most of the screens for Super Jumper. We
clear the screen and set up the projection matrix via our camera. We enable texturing and then
immediately render the background via the
SpriteBatcher
and
TextureRegion
we defined in
the
Assets
class. The menu items have translucent areas, so we enable blending before we
render them.
@Override
public void
pause() {
}