com.siemens.mp.game
Class TiledBackground

java.lang.Object
  extended bycom.siemens.mp.misc.NativeMem
      extended bycom.siemens.mp.game.GraphicObject
          extended bycom.siemens.mp.game.TiledBackground

public class TiledBackground
extends GraphicObject

The TiledBackground class implements tiled pictures for the display background. For setting a tiled background for display, the user must first define 8x8 pixel tiles and, optionally, their masks; then create a map with tiles indexes. This map defines how tiles will be placed on the background; if the map size is less than the display size, it will be repeated throughout all the display.

The map may contain both user-defined tiles and predefined (0 = transparent, 1 = white and 2 = black) tiles. The user-defined tile indexes in a map start from 3 (3 for the first user tile, 4 for the second, etc.)

Because the TiledBackground class is a subclass of GraphicObject, it has no direct drawing capability available for the user. Instead, when included into a GraphicObjectManager collection, a tiled background will be drawn in proper order by the GraphicObjectManager.paint method call.

See Also:
GraphicObject, GraphicObjectManager

Example


Constructor Summary
TiledBackground(byte[] tilePixels, byte[] tileMask, byte[] map, int widthInTiles, int heightInTiles)
          Creates tiled background using tiles from a bytearray.
TiledBackground(ExtendedImage tilePixels, ExtendedImage tileMask, byte[] map, int widthInTiles, int heightInTiles)
          Creates tiled background using tiles from an ExtendedImage object.
TiledBackground(Image tilePixels, Image tileMask, byte[] map, int widthInTiles, int heightInTiles)
          Creates a tiled background using tiles from an Image object.
 
Method Summary
 void setPositionInMap(int x, int y)
          Sets the point in the tiles map that will correspond to the drawing area starting point.
 
Methods inherited from class com.siemens.mp.game.GraphicObject
getVisible, setVisible
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TiledBackground

public TiledBackground(Image tilePixels,
                       Image tileMask,
                       byte[] map,
                       int widthInTiles,
                       int heightInTiles)
                throws IllegalArgumentException
Creates a tiled background using tiles from an Image object. The tilePixels image width must be 8 (all tiles in one column), its height is (tiles count)*8.

The tileMask image size must be equal to the tilePixels image size. It defines tiles transparency (like the Sprite mask). This parameter may be null.

The map contains tile indexes (one byte per tile). There are 3 predefined tiles: tile 0 is a transparent tile, tile 1 is a white tile, tile 2 is a black tile. User-defined tiles start at 3 (3 for the first user tile, 4 for the second, etc.)

Parameters:
tilePixels - a standard Image containing tiles (8x8); the width of the image must be 8
tileMask - a standard Image containing tile masks (8x8); the width of the image must be 8. This parameter may be null.
map - a byte array with the map for the tiles (one byte per tile)
widthInTiles - the map width in tiles
heightInTiles - the map height in tiles
Throws:
IllegalArgumentException - if the width of the image/mask is not 8
if transparent color is used in the image/mask
if there is a wrong tile number in the map

Example


TiledBackground

public TiledBackground(ExtendedImage tilePixels,
                       ExtendedImage tileMask,
                       byte[] map,
                       int widthInTiles,
                       int heightInTiles)
                throws IllegalArgumentException
Creates tiled background using tiles from an ExtendedImage object. The tilePixels image width must be 8 (all tiles in one column), its height is (tiles count)*8.

The tileMask image size must be equal to the tilePixels image size. It defines tiles transparency (like the Sprite mask). This parameter may be null.

The map contains tile indexes (one byte per tile). There are 3 predefined tiles: tile 0 is a transparent tile, tile 1 is a white tile, tile 2 is a black tile. User-defined tiles start at 3 (3 for the first user tile, 4 for the second, etc.)

Parameters:
tilePixels - an ExtendedImage with the tiles (8x8); the width of the image must be 8
tileMask - an ExtendedImage with the tile masks (8x8); the width of the image must be 8. This parameter may be null.
map - a byte array with the map for the tiles (one byte per tile)
widthInTiles - the map width in tiles
heightInTiles - the map height in tiles
Throws:
IllegalArgumentException - if the width of the image/mask is not 8
if transparent color is used in the image/mask
if there is a wrong tile number in the map

Example


TiledBackground

public TiledBackground(byte[] tilePixels,
                       byte[] tileMask,
                       byte[] map,
                       int widthInTiles,
                       int heightInTiles)
                throws IllegalArgumentException
Creates tiled background using tiles from a bytearray. The tilePixels bytearray contains tiles in one-bit-per-pixel (1bpp) format. Its' size in bytes equals 8*(number of tiles).

The tileMasks bytearray contains tile masks in one-bit-per-pixel (1bpp) format. Its' size must be equal to the tilePixels array size. It defines tiles transparency (like the Sprite mask). This parameter may be null.

The map contains tile indexes (one byte per tile). There are 3 predefined tiles: tile 0 is a transparent tile, tile 1 is a white tile, tile 2 is a black tile. User-defined tiles start at 3 (3 for the first user tile, 4 for the second, etc.)

Parameters:
tilePixels - a bytearray with the tiles (8x8) (1bpp)
tileMask - a bytearray with the masks of the tiles (8x8) (1bpp). This parameter may be null.
map - a byte array with the map for the tiles (one byte per tile)
widthInTiles - the map width in tiles
heightInTiles - the map height in tiles
Throws:
IllegalArgumentException - if the size of the tiles/mask array is not a multiple of 8
if there is a wrong tile number in the map
See Also:
GraphicObjectManager.createTextureBits

Example

Method Detail

setPositionInMap

public void setPositionInMap(int x,
                             int y)
Sets the point in the tiles map that will correspond to the drawing area starting point. The tiles drawing will start from that point.

Parameters:
x - the x coordinate of the point on the map, in pixels
y - the y coordinate of the point on the map, in pixels
See Also:
GraphicObjectManager.paint

Example



Generated on 2003-10-17For further information and updates, please visit Siemens mobile Developer Portal