Game Development Reference
In-Depth Information
We have the GLScreen.update() method as the master method again, which calls one of the
other update methods depending on the current state of the screen. Note that we limit the delta
time to 0.1 seconds. Why do we do that? In Chapter 7, we talked about a bug in the direct byte
buffers in Android version 1.5, which generates garbage. We will have that problem in Super
Jumper as well on Android 1.5 devices. Every now and then, our game will be interrupted for
a few hundred milliseconds by the garbage collector. This would be reflected in a delta time of
a few hundred milliseconds, which would make Bob sort of teleport from one place to another
instead of smoothly moving there. That's annoying for the player, and it also has an effect on our
collision detection. Bob could tunnel through a platform without ever overlapping with it, due to
him moving a large distance in a single frame. By limiting the delta time to a sensible maximum
value of 0.1 seconds, we can compensate for those effects.
private void updateReady() {
if if(game.getInput().getTouchEvents().size() > 0) {
state = GAME _ RUNNING ;
}
}
The updateReady() method is invoked in the paused subscreen. All it does is wait for a touch
event, in which case it will change the state of the game screen to the GAME_RUNNING state.
private void updateRunning( float deltaTime) {
List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
int len = touchEvents.size();
for ( int i = 0; i < len; i++) {
TouchEvent event = touchEvents.get(i);
if (event.type != TouchEvent. TOUCH _ UP )
continue ;
touchPoint.set(event.x, event.y);
guiCam.touchToWorld(touchPoint);
if (OverlapTester. pointInRectangle (pauseBounds, touchPoint)) {
Assets. playSound (Assets. clickSound );
state = GAME _ PAUSED ;
return ;
}
}
world.update(deltaTime, game.getInput().getAccelX());
if if(world.score != lastScore) {
lastScore = world.score;
scoreString = "" + lastScore;
}
if if(world.state == World. WORLD _ STATE _ NEXT _ LEVEL ) {
state = GAME _ LEVEL _ END ;
}
if if(world.state == World. WORLD _ STATE _ GAME _ OVER ) {
state = GAME _ OVER ;
if if(lastScore >= Settings. highscores [4])
scoreString = "new highscore: " + lastScore;
Search WWH ::




Custom Search