January 2014
Intermediate to advanced
736 pages
70h 43m
English
Figure 6.20 defines a subclass of Thread which updates the game. The thread maintains a reference to the SurfaceView’s SurfaceHolder (line 538) and a boolean indicating whether the thread is running. The class’s run method (lines 556–587) drives the frame-by-frame animations—this is known as the game loop. Each update of the game elements on the screen is performed based on the number of milliseconds that have passed since the last update. Line 559 gets the system’s current time in milliseconds when the thread begins running. Lines 561–586 loop until threadIsRunning is false.
535 // Thread subclass to control the game loop536 private class CannonThread ...
Read now
Unlock full access