J2ME Gaming API: An Overview
A D V E R T I S E M E N T
There are only five classes in the javax.microedition.lcdui.game
package: GameCanvas, Layer, Sprite,
TiledLayer, and LayerManager. These five classes are enough
to provide a platform for the development of games with a wide range of
capabilities.
The Layer class is the superclass of the Sprite and
TiledLayer classes. This class abstracts the behavior of a visual
element in a game. This element can be a sprite, which represents an
independent graphic (or a collection of graphics for animation) that can be
moved around the game screen, or a tiled layer, which represents a
graphic that can be used to create vast game backgrounds with only a handful of
images. You use the Layer classes for positioning and visibility.
The subclasses override the paint(Graphics g) method, which has the
task of rendering the elements on the screen.
The LayerManager class provides a convenient mechanism to manage
the various visual elements of a game (sprites and tiled layers) by rendering
the proper layer in the proper order.
The GameCanvas class is made useful by extending the
functionality of the Canvas class . It provides an off-screen
buffer, to which all rendering operations are done before flushing them on the
device screen. It also provides an easy-to-use mechanism to query the current
keys being pressed by the user.
The best way to introduce you to these classes is with the help of a working
game example, which we will build from the ground up, explaining the various
facets of a game. This is helpful whether or not you have programmed a game
before, if you are looking to learn how to do it for the wireless devices using
J2ME's gaming API. After a quick introduction to game building (for those who
have never created a game), the remaining sections introduce each of the classes
from the javax.microedition.lcdui.game package, with the help of a
concise but complete game.
|