Java Reference
In-Depth Information
games. As you read through this section, spare a thought for those early
pioneers who had to build all of this from scratch.
8.3.1 The Full-Screen Canvas
The game canvas supplied as part of MIDP 2.0 allows the game to take
over the full screen real estate - or at least as much as the implementation
allows (UIQ devices do not allow complete use but they tend to have
larger screens in any case). Prior to this, developers were stuck with
even smaller areas than are around today, unless they leveraged custom
libraries provided by the phone manufacturers. One example of this was
the Nokia UI which provided a full-screen canvas.
8.3.2 Game Key Mappings
These are an abstraction of the basic actions taken by players during a
game. In most cases, these actions are moving left or right, up or down
and triggering some action such as firing a weapon or jumping. This
allows Java ME game code to work over a variety of hardware input
methods as each manufacturer can map, for example, the UP action to
an input method best suited to the device.
Game actions are defined as fields of the Canvas class. The code
snippet below demonstrates how to extract the game action in an event
public void keyPressed(int keyCode) {
int gameAction = getGameAction(keyCode);
switch(gameAction) {
case Canvas.FIRE: ...
case Canvas.UP: ...
8.3.3 Painting and Double Buffering
The GameCavas provides double buffering by default. The painting
model is such that all drawing occurs to an offscreen buffer which is then
sent to the display using the flushGraphics() method. As a devel-
oper, your task is to provide an implementation of the paint() method.
It is called by the framework: you should never call this method yourself.
Application-initiated painting is done via the repaint() and ser-
viceRepaints() methods. Calling repaint() only issues a request
to update the screen - it completes immediately and the framework calls
your paint() method asynchronously. In this manner, a number of
calls to repaint() may actually result in only a single update. The
serviceRepaints() method is synchronous and forces any pending
Search WWH ::

Custom Search