BenQ Mobile

javax.microedition.lcdui.game
Class Layer

java.lang.Object
  extended byjavax.microedition.lcdui.game.Layer
Direct Known Subclasses:
Sprite, TiledLayer

public abstract class Layer
extends java.lang.Object

Description:

A Layer is an abstract class representing a visual element of a game. Each Layer has position (in terms of its upper-left corner), width, height, and can be made visible or invisible. Layer subclasses must implement a paint(Graphics) method such that they can be rendered.


Method Summary
 int getHeight()
          Gets the current height of this layer, in pixels.
 int getWidth()
          Gets the current width of this layer, in pixels.
 int getX()
          Gets the horizontal position of this Layer’s upper-left corner.
 int getY()
          Gets the vertical position of this Layer’s upper-left corner.
 boolean isVisible()
          Gets the visibility of this Layer.
 void move(int dx, int dy)
          Moves this Layer by the specified horizontal and vertical distances.
abstract  void paint(Graphics g)
          Paints this Layer if it is visible.
 void setPosition(int x, int y)
          Sets this Layer’s position by specifying the location of its upper-left corner.
 void setVisible(boolean visible)
          Sets the visibility of this Layer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getHeight

public final int getHeight()
Gets the current height of this layer, in pixels.

Returns:
The height in pixels

getWidth

public final int getWidth()
Gets the current width of this layer, in pixels.

Returns:
The width in pixels

getX

public final int getX()
Gets the horizontal position of this Layer’s upper-left corner.

Returns:
The Layer’s x position.

getY

public final int getY()
Gets the vertical position of this Layer’s upper-left corner.

Returns:
The Layer’s y position.

isVisible

public final boolean isVisible()
Gets the visibility of this Layer.

Returns:
True if the Layer is visible, false if it is invisible.

move

public void move(int dx,
                 int dy)
Moves this Layer by the specified horizontal and vertical distances.

Parameters:
dx - Distance to move along horizontal axis (positive to the right, negative to the left)
dy - Distance to move along vertical axis (positive down, negative up)

paint

public abstract void paint(Graphics g)
Paints this Layer if it is visible. The upper-left corner of the Layer is rendered at it’s current (x,y) position relative to the origin of the provided Graphics object. Applications may make use of Graphics clipping and translation to control where the Layer is rendered and to limit the region that is rendered.

Implementations of this method are responsible for checking if this Layer is visible; this method does nothing if the Layer is not visible.

Implementations of this method may modify the origin and clip region of the Graphics object in order to render the layer. However, they may not expand the clip region, and both the clip region and origin translation MUST be restored to their original values before this method returns. Also, implementations should not make any assumptions regarding the state of the Graphics object (drawing color, font, line style, etc.).

Parameters:
g - Graphics object for rendering the Layer
Throws:
java.lang.NullPointerException - if g is null

setPosition

public void setPosition(int x,
                        int y)
Sets this Layer’s position by specifying the location of its upper-left corner.
A Layer is located at (0,0) by default.

Parameters:
x - The horizontal position
y - The vertical position

setVisible

public void setVisible(boolean visible)
Sets the visibility of this Layer. A visible Layer is rendered when its paint(Graphics)309 method is called; an invisible Layer is not rendered.

Parameters:
visible - True to make the Layer visible, false to make it invisible

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.