The rest of the Game API is devoted to layers. Layers are graphic elements that can be combined to create a complete scene. You might, for example, have a background of mountains, another background of city buildings, and several smaller items in the foreground: people, spaceships, cars, whatever.
The technique of combining layers resembles traditional hand-drawn animations. Background and foreground images are drawn on transparent cels, which are placed one on top of another and photographed to create the final scene.
In the Game API, an instance of the javax.microedition.lcdui.game.Layer class represents a layer. Layer is abstract, with two concrete subclasses. Layer itself is pretty straightforward. It has a location, a size, and can be visible or invisible. The location and size are accessed and modified with the following methods, which are self-explanatory:
public final int getX() public final int getY() public final int getWidth() public final int getHeight() public void setPosition(int x, int y)
Layer also offers a handy method for moving relative to the current position. Pass pixel offsets to the following method to adjust the position of the layer:
public void move(int dx, int dy)
The layer's visibility is accessed using getVisible() and setVisible().
The last method in Layer is paint(), which is declared abstract. Subclasses override this method to define their appearance.