org.piratis.j2me.core.game
Class TiledLayer

java.lang.Object
  extended byorg.piratis.j2me.core.game.Layer
      extended byorg.piratis.j2me.core.game.TiledLayer

public class TiledLayer
extends Layer

A type of Layer composed of a grid of cells which can contain a reduced set of predefined images. This class allows large virtual layers to be created without the need for an extremely large Image. It is commonly used to creat very large scrolling backgrounds.

Version:
$Id: TiledLayer.java,v 1.5 2004/07/29 20:13:06 piratis Exp $
Author:
Jordi Martín

Field Summary
 
Fields inherited from class org.piratis.j2me.core.game.Layer
bbox, TOP_LEFT, visible
 
Constructor Summary
TiledLayer(int columns, int rows, Image image, int tileWidth, int tileHeight)
          Creates a new TiledLayer.
 
Method Summary
 boolean cellCollides(Layer l)
          Check colliding but checking cells.
 int createCommonTile(int tileIndex)
          Cretates a new common tile returning the index referring to this new common tile.
 void fillCells(int col, int row, int colNumber, int rowNumber, int tileIndex)
          Sets the given tileIndex in a given region.
 int getCell(int col, int row)
          Gets cell's contents
 int getCommonTile(int commonTileIndex)
          Gets the tile referenced by the given common tile.
 void paint(Graphics g)
          Paints this layer if it is visible.
 void setCell(int col, int row, int tileIndex)
          Sets the contents of a cell.
 void setCommonTile(int commonTileIndex, int tileIndex)
          Changes the tile associated to this common tile.
 
Methods inherited from class org.piratis.j2me.core.game.Layer
getBbox, isVisible, moveBy, moveTo, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TiledLayer

public TiledLayer(int columns,
                  int rows,
                  Image image,
                  int tileWidth,
                  int tileHeight)
Creates a new TiledLayer.

TODO:

Parameters:
columns -
rows -
image -
tileWidth -
tileHeight -
Method Detail

fillCells

public void fillCells(int col,
                      int row,
                      int colNumber,
                      int rowNumber,
                      int tileIndex)
Sets the given tileIndex in a given region.

Parameters:
col - top-left region column
row - top-left region row
colNumber - region col number
rowNumber - region row number
tileIndex - tile index to set

setCell

public void setCell(int col,
                    int row,
                    int tileIndex)
Sets the contents of a cell.

Parameters:
col - column from the grid
row - row from the grid
tileIndex - the index of the tile

getCell

public int getCell(int col,
                   int row)
Gets cell's contents

Parameters:
col - column from the grid
row - row from the grid
Returns:
the index of the tile in the cell

createCommonTile

public int createCommonTile(int tileIndex)
Cretates a new common tile returning the index referring to this new common tile. It is initially assigned with the provided tileIndex.

Parameters:
tileIndex -
Returns:

getCommonTile

public int getCommonTile(int commonTileIndex)
Gets the tile referenced by the given common tile.

Parameters:
commonTileIndex - the index of the common tile.
Returns:
the tile index currently associated with the common tile.

setCommonTile

public void setCommonTile(int commonTileIndex,
                          int tileIndex)
Changes the tile associated to this common tile.

Parameters:
commonTileIndex -
tileIndex -

paint

public void paint(Graphics g)
Description copied from class: Layer
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!

Specified by:
paint in class Layer
Parameters:
g - the graphics object for rendering this layer
See Also:
org.piratis.j2me.core.game.Layer#paint(javax.microedition.lcdui.Graphics)

cellCollides

public boolean cellCollides(Layer l)
Check colliding but checking cells.

Parameters:
l - Layer to check
Returns:
whether colliding exists

Copyright(c) 2003-2004 Jordi Martin