javax.microedition.lcdui.game
Class Layer

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

public abstract class Layer
extends Object

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

The Layer's (x,y) position is always interpreted relative to the coordinate system of the Graphics object that is passed to the Layer's paint() method. This coordinate system is referred to as the painter's coordinate system. The initial location of a Layer is (0,0).

Since:
BlackBerry API 4.0.0, MIDP 2.0

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 in the painter's coordinate system.
 int getY()
          Gets the vertical position of this Layer's upper-left corner in the painter's coordinate system.
 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 such that its upper-left corner is located at (x,y) in the painter's coordinate system.
 void setVisible(boolean visible)
          Sets the visibility of this Layer.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 



Method Detail

setPosition

public void setPosition(int x,
                        int y)
Sets this Layer's position such that its upper-left corner is located at (x,y) in the painter's coordinate system. A Layer is located at (0,0) by default.

Parameters:
x - the horizontal position
y - the vertical position
See Also:
Layer.move(int, int), Layer.getX(), Layer.getY()
Since:
BlackBerry API 4.0.0

move

public void move(int dx,
                 int dy)
Moves this Layer by the specified horizontal and vertical distances.
The Layer's coordinates are subject to wrapping if the passed parameters will cause them to exceed beyond Integer.MAX_VALUE or Integer.MIN_VALUE.

Parameters:
dx - the distance to move along horizontal axis (positive to the right, negative to the left)
dy - the distance to move along vertical axis (positive down, negative up)
See Also:
Layer.setPosition(int, int), Layer.getX(), Layer.getY()
Since:
BlackBerry API 4.0.0

getX

public final int getX()
Gets the horizontal position of this Layer's upper-left corner in the painter's coordinate system.

Returns:
the Layer's horizontal position.
See Also:
Layer.getY(), Layer.setPosition(int, int), Layer.move(int, int)
Since:
BlackBerry API 4.0.0

getY

public final int getY()
Gets the vertical position of this Layer's upper-left corner in the painter's coordinate system.

Returns:
the Layer's vertical position.
See Also:
Layer.getX(), Layer.setPosition(int, int), Layer.move(int, int)
Since:
BlackBerry API 4.0.0

getWidth

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

Returns:
the width in pixels
See Also:
Layer.getHeight()
Since:
BlackBerry API 4.0.0

getHeight

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

Returns:
the height in pixels
See Also:
Layer.getWidth()
Since:
BlackBerry API 4.0.0

setVisible

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

Parameters:
visible - true to make the Layer visible, false to make it invisible
See Also:
Layer.isVisible()
Since:
BlackBerry API 4.0.0

isVisible

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

Returns:
true if the Layer is visible, false if it is invisible.
See Also:
Layer.setVisible(boolean)
Since:
BlackBerry API 4.0.0

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.

The attributes of the Graphics object (clip region, translation, drawing color, etc.) are not modified as a result of calling this method.

Parameters:
g - the graphics object for rendering the Layer
Throws:
NullPointerException - if g is null
Since:
BlackBerry API 4.0.0





Copyright 1999-2010 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark of Sun Microsystems, Inc.