Game Development Reference
In-Depth Information
framebuffer. The scaling is performed automatically in case the destination rectangle we pass to
the Canvas.drawBitmap() method is smaller or bigger than the framebuffer.
Note that we've used a shortcut here to get a destination rectangle that stretches over the whole
SurfaceView via the Canvas.getClipBounds() method. It will set the top and left members
of dstRect to 0 and 0, respectively, and the bottom and right members to the actual screen
dimensions (480×800 in portrait mode on a Nexus One). The rest of the method is exactly the
same as what we had in our FastRenderView test in the last chapter. The method simply makes
sure that the thread stops when the activity is paused or destroyed.
public void pause() {
running= false ;
while ( true ) {
try {
renderThread.join();
return ;
} catch (InterruptedException e) {
// retry
}
}
}
}
The last method of this class, pause() , is also the same as in the FastRenderView.pause()
method—it simply terminates the rendering/main loop thread and waits for it to die completely
before returning.
We are nearly done with our framework. The last piece of the puzzle is the implementation of the
Game interface.
AndroidGame: Tying Everything Together
Our game development framework is nearly complete. All we need to do is tie the loose ends
together by implementing the Game interface we designed in Chapter 3. To do this, we will use
the classes we created in the previous sections of this chapter. The following is a list
of responsibilities:
ï?®
Perform window management. In our context, this means setting up an
activity and an AndroidFastRenderView , and handling the activity life cycle in
a clean way.
WakeLock so that the screen does not dim.
Instantiate and hand out references to
ï?®
Use and manage a
Graphics , Audio , FileIO , and Input to
ï?®
interested parties.
ï?® Screen s and integrate them with the activity life cycle.
Our general goal is it to have a single class called
Manage
ï?® AndroidGame from which
we can derive. We want to implement the Game.getStartScreen() method
later on to start our game in the following way.
 
Search WWH ::




Custom Search