Game API (Java Developer's Library)
The Game API is a set of Java classes which enable easier development of rich gaming content on MIDP 2.0 enabled mobile devices. The Game API classes are stored in the javax.microedition.lcdui.game package and included into the standard MIDP 2.0.
The Game API classes are: GameCanvas, Layer, LayerManager, Sprite and TiledLayer.
GameCanvas is an extension of the standard Canvas class from the LCDUI. The main features of the GameCanvas are controlled graphics flushing and ability to query states of the game keys. Quite many mobile platforms are supporting GameCanvas with double-buffering for the graphical content to provide smooth image animations on the mobile display.
Layer is an abstract class representing a visual element of a game. Each Layer has its position (in terms of the upper-left corner of its visual bounds), width, height, and can be made visible or invisible.
The LayerManager manages a series of Layers. The LayerManager simplifies the process of rendering the Layers that have been added to it by automatically rendering the correct regions of each Layer in the appropriate order.
Sprite is a basic visual element that can be rendered with one of several frames stored in an Image; different frames can be shown to animate the Sprite. Several transforms such as flipping and rotation can also be applied to a Sprite to further vary its appearance. As with all Layer subclasses, a Sprite's location can be changed and it can also be made visible or invisible.
A TiledLayer is a visual element composed of a grid of cells that can be filled with a set of tile images. This class allows large virtual layers to be created without the need for an extremely large Image. This technique is commonly used in 2D gaming platforms to create very large scrolling backgrounds or game fields.
- JSR 118 (MIDP 2.0) specification
- Java online documentation (oracle.com)
- Game API online documentation (docs.oracle.com)
- Getting Started with Java Game API (oracle.com)