12.1. The GameCanvas API

The Canvas class was designed for applications that are event-driven; that is, the user interface is updated in response to a user input, such as selecting an option or pressing a soft key. However, game applications are generally time-driven and continue to run and update the display whether or not the user provides input. To overcome this difference, the GameCanvas class provides a game-centric model for accessing the display and checking for key inputs.

Game applications typically employ a single thread to run the game. This thread executes a main loop, shown in Figure 12.1, that repeatedly checks for user input, implements logic to update the state of the game, and then updates the user interface to reflect the new ...

Get Programming Wireless Devices with the Java™ 2 Platform, Micro Edition, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.