Java Reference
In-Depth Information
index. While positive indices are direct pointers to a portion of the source image, negative indices are
indirect pointers and can be remapped for animating a set of cells with the same virtual index at once.
An index of zero represents a transparent cell.
Both classes, Sprite and TiledLayer are derived from the abstract class Layer . While instances
of both classes can be drawn directly using their paint method, the game package also contains a
LayerManager that can manage a set of graphical objects including their Z-Order.
Finally, the game package contains the class GameCanvas , a subclass of Canvas . Each instance of
GameCanvas has its own offscreen buffer. In contrast to the simple Canvas , it is safe to assume that
the GameCanvas offscreen buffer is not obscured. Moreover, the GameCanvas provides access to
the corresponding Graphics object outside of the paint method and a method to flush the offscreen
buffer to the screen.
The Media Packages
The javax.microedition.media package contains audio support and consists of three main
building blocks. The Manager class can be seen as the entry point to media access. It is able to list the
supported media types and create new Player instances. A player can be used to actually play a
media object, such as a midi or mp3 file (depending on the supported media types).
The code snipped below shows an example of how to play a midi file from the Web using a player
object obtained from the Manager.
try {
Player p = Manager.createPlayer("http://ringtones.org/song.mid");
p.start();
}
catch (MediaException pe) {
}
catch (IOException ioe) {
}
The javax.microedition.media.control package contains additional components for
controlling the properties of the played media objects such as volume and pitch.
Summary
In this chapter, you learned the general life cycle of MIDP applications. You know how to build a
user interface using the high-level lcdui widgets, and how to interact using the listener
mechanism. You have learned to perform custom graphics using the low-level API, including
device-independent flicker-free animation and coordination of graphics calculation and drawing.
The next chapter gives a corresponding overview of the PDAP life cycle and user interface. The
PDAP introduction focuses on the differences between the J2SE AWT classes and the subset
included in PDAP, but still gives a basic introduction to AWT programming.
 
Search WWH ::




Custom Search