Java Reference
In-Depth Information
its most abstract level, a game loop can be thought of as a continuous
process of checking for user input, updating the game world and then
repainting the screen to display the new state of the world to the user.
Unlike mainstream game platforms, mobile phone games must execute
on a large and diverse range of target hardware. So in reality there are a
couple more steps that need to occur to keep things running smoothly.
Not all topics include these steps, and some change the order or absorb
some steps into others. Figure 8.1 shows the main steps in the game loop
as described in [Stichbury 2008].
Calculate time elapsed
Rertrieve user input
Update game internals
Update graphics
Synchronize audio
Figure 8.1 The Game Loop from [Stichbury 2008]
In this chapter, we vary this very slightly. Notice that when laid out
step by step the process of building a game loses some of its mystery and
actually becomes quite mechanical.
In pseudo-code, our generic game loop is:
while (game not stopped)
check if game over
retrieve and handle user input
update game world internals (physics/AI)
update graphics
synchronize events before next loop
Jumping ahead a bit, the implementation then becomes pretty straight-
forward - you simply create a game thread and these steps translate
directly into a series of method calls in the run() method of
Runnable object.
Search WWH ::

Custom Search