org.piratis.j2me.core.game
Class Layer

java.lang.Object
  extended byorg.piratis.j2me.core.game.Layer
Direct Known Subclasses:
Sprite, TiledLayer

public abstract class Layer
extends java.lang.Object

Abstract class representing a visual element of a game. Each Layer has its Bounding Box (position plus width and height) and visibility features. It is mandatory for subclasses to implement the paint(Graphics) method!

Bear in mind that the layer's position is always relative to the Graphics coordinate system.

Version:
$Id: Layer.java,v 1.2 2004/07/01 22:16:44 piratis Exp $
Author:
Jordi Martín

Field Summary
protected  BBox2D bbox
          Own's bbox (initially empty!)
static int TOP_LEFT
           
protected  boolean visible
          Visibility management
 
Constructor Summary
Layer()
           
 
Method Summary
 BBox2D getBbox()
          Returns own bounding box, always in pixel values
 boolean isVisible()
          Gets the visibility of this layer
 void moveBy(int dx, int dy)
          Moves the current layer the given horizontal and vertical distances.
 void moveTo(int x, int y)
          Moves the layer's top-left corner at the given (x,y) coordinates
abstract  void paint(Graphics g)
          Paints this layer if it is visible.
 void setVisible(boolean newVisible)
          Sets the visibility of the layer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TOP_LEFT

public static int TOP_LEFT

bbox

protected BBox2D bbox
Own's bbox (initially empty!)


visible

protected boolean visible
Visibility management

Constructor Detail

Layer

public Layer()
Method Detail

getBbox

public BBox2D getBbox()
Returns own bounding box, always in pixel values

Returns:
the Layer's bounding box
See Also:
BBox2D

isVisible

public boolean isVisible()
Gets the visibility of this layer

Returns:
true if the layer is visible, falseotherwise.

setVisible

public void setVisible(boolean newVisible)
Sets the visibility of the layer. Will or won't be rendered according to this property value.

Parameters:
newVisible - true to make this layer visible, false otherwise.

moveBy

public void moveBy(int dx,
                   int dy)
Moves the current layer the given horizontal and vertical distances.

Parameters:
dx - horizontal axis distance (positive to the right, negative to the left)
dy - vertical axis distance (positive downwards, negative upwards)

moveTo

public void moveTo(int x,
                   int y)
Moves the layer's top-left corner at the given (x,y) coordinates

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

paint

public abstract void paint(Graphics g)
Paints this layer if it is visible.

Implementors are responsible of checking this condition before painting the layer: must do nothing when it is not visible. They must also ensure that the attributes of the Graphics object are not modified when returning from the call of this method!

Parameters:
g - the graphics object for rendering this layer

Copyright(c) 2003-2004 Jordi Martin