BenQ Mobile

javax.microedition.lcdui.game
Class LayerManager

java.lang.Object
  extended byjavax.microedition.lcdui.game.LayerManager

public class LayerManager
extends java.lang.Object

Description:

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.

The LayerManager maintains an ordered list to which Layers can be appended, inserted and removed. A Layer’s index correlates to its z-order; the layer at index 0 is closest to the user while a the Layer with the highest index is furthest away from the user. The indicies are always contiguous; that is, if a Layer is removed, the indicies of subsequent Layers will be adjusted to maintain continuity. The LayerManager class provides several features that control how the game’s Layers are rendered on the screen.

The view window controls the size of the visible region and its position relative to the LayerManager’s coordinate system. Changing the position of the view window enables effects such as scrolling or panning the user’s view. For example, to scroll to the right, simply move the view window’s location to the right. The size of the view window controls how large the user’s view will be, and is usually fixed at a size that is appropriate for the device’s screen.


Constructor Summary
LayerManager()
          Creates a new LayerManager.
 
Method Summary
 void append(Layer l)
          Appends a Layer to this LayerManager.
 Layer getLayerAt(int index)
          Gets the Layer with the specified index.
 int getSize()
          Gets the number of Layers in this LayerManager.
 void insert(Layer l, int index)
          Inserts a new Layer in this LayerManager at the specified index.
 void paint(Graphics g, int x, int y)
          Renders the LayerManager’s current view window at the specified location.
 void remove(Layer l)
          Removes the specified Layer from this LayerManager.
 void setViewWindow(int x, int y, int width, int height)
          Sets the view window on the LayerManager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LayerManager

public LayerManager()
Creates a new LayerManager.

Method Detail

append

public void append(Layer l)
Appends a Layer to this LayerManager. The Layer is appended to the list of existing Layers such that it has the highest index (i.e. it is furthest away from the user). The Layer is first removed from this LayerManager if it has already been added.

Parameters:
l - The Layer to be added
Throws:
java.lang.NullPointerException - if the Layer l is null

getLayerAt

public Layer getLayerAt(int index)
Gets the Layer with the specified index.

Parameters:
index - The index to search for
Returns:
The Layer that has the specified index
Throws:
java.lang.IndexOutOfBoundsException - if the specified index is less than zero, or if it is equal to or greater than the number of Layers added to the this LayerManager

getSize

public int getSize()
Gets the number of Layers in this LayerManager.

Returns:
the number of Layers

insert

public void insert(Layer l,
                   int index)
Inserts a new Layer in this LayerManager at the specified index. The Layer is first removed from this Layer Manager if it has already been added.

Parameters:
l - The Layer to be inserted
index - The index at which the new Layer is to be inserted
Throws:
java.lang.NullPointerException - if the Layer is null
java.lang.IndexOutOfBoundsException - if the index is less than 0 or greater than the number of Layers already added to the this LayerManager

paint

public void paint(Graphics g,
                  int x,
                  int y)
Renders the LayerManager’s current view window at the specified location. The LayerManager renders each of its layers in order of descending index, thereby implementing the correct z-order. Layers that are completely outside of the view window are not rendered.

The coordinates passed to this method determine where the LayerManager’s view window will be rendered relative to the origin of the Graphics object. For example, a game may use the top of the screen to display the current score, so to render the game’s layers below that area, the view window might be rendered at (0, 20). The location is relative to the Graphics object’s origin, so translating the Graphics object will change where the view window is rendered on the screen.

Rendering is subject to the clip region and translation of the Graphics object. Thus, only part of the speci- fied view window may be rendered if the clip region is not large enough.

Parameters:
g - Graphics instance on which to draw the LayerManager
x - The horizontal location at which to render the view window, relative to the Graphics’ origin
y - The vertical location at which to render the view window, relative to the Graphics’ origin
Throws:
java.lang.NullPointerException - if g is null

remove

public void remove(Layer l)
Removes the specified Layer from this LayerManager. This method does nothing if the specified Layer is not added to the this LayerManager.

Parameters:
l - The Layer to be removed Throws: java.lang.NullPointerException if the specified Layer is null

setViewWindow

public void setViewWindow(int x,
                          int y,
                          int width,
                          int height)
Sets the view window on the LayerManager.
The view window specifies the region that the LayerManager draws when its paint(Graphics, int, int) method is called. It allows the developer to control the size of the visible region, as well as the location of the view window relative to the LayerManager’s coordinate system.

The view window stays in effect until it is modified by another call to this method. By default, the view window is set to the screen dimensions and is located at 0,0.

Parameters:
x - The horizontal location of the view window relative to the LayerManager’s origin
y - The vertical location of the view window relative to the LayerManager’s origin
width - The Width of the view window
height - The Height of the view window
Throws:
java.lang.IllegalArgumentException - if the width or height is less than 0

BenQ Mobile

Copyright © 2006 BenQ Mobile GmbH & Co. OHG or respective copyright owner.
All Rights Reserved.
BenQ Corp. is a trademark licensee of Siemens AG.


For further information about Mobility Toolkit (MTK) visit our Developer Portal.