Game Development Reference
In-Depth Information
playBounds = new Rectangle(160 - 150, 200 + 18, 300, 36);
highscoresBounds = new Rectangle(160 - 150, 200 - 18, 300, 36);
helpBounds = new Rectangle(160 - 150, 200 - 18 - 36, 300, 36);
touchPoint = new Vector2();
}
In the constructor, we simply set up all the members. And there's a surprise. The Camera2D
instance will allow us to work in our target resolution of 320×480 pixels. All we need to do is
set the view frustum width and height to the proper values. The rest is done by OpenGL ES on
the fly. Note, however, that the origin is still in the bottom-left corner and the y axis is pointing
upward. We'll use such a GUI camera in all screens that have UI elements so that we can lay
them out in pixels instead of world coordinates. Of course, we cheat a little on screens that are
not 320×480 pixels wide, but we already did that in Mr. Nom, so we don't need to feel bad about
it. The Rectangles we set up for each UI element are thus given in pixel coordinates.
@Override
public void update( float deltaTime) {
List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
game.getInput().getKeyEvents();
int len = touchEvents.size();
for ( int i = 0; i < len; i++) {
TouchEvent event = touchEvents.get(i);
if (event.type == TouchEvent. TOUCH _ UP ) {
touchPoint.set(event.x, event.y);
guiCam.touchToWorld(touchPoint);
if (OverlapTester. pointInRectangle (playBounds, touchPoint)) {
Assets. playSound (Assets. clickSound );
game.setScreen( new GameScreen(game));
return ;
}
if (OverlapTester. pointInRectangle (highscoresBounds, touchPoint)) {
Assets. playSound (Assets. clickSound );
game.setScreen( new HighscoreScreen(game));
return ;
}
if (OverlapTester. pointInRectangle (helpBounds, touchPoint)) {
Assets. playSound (Assets. clickSound );
game.setScreen( new HelpScreen(game));
return ;
}
if (OverlapTester. pointInRectangle (soundBounds, touchPoint)) {
Assets. playSound (Assets. clickSound );
Settings. soundEnabled = !Settings. soundEnabled ;
if (Settings. soundEnabled )
Assets. music .play();
else
Assets. music .pause();
}
}
}
}
Search WWH ::




Custom Search