e2d::graphics::MapLayer Class Reference

List of all members.


Detailed Description

A map of tiles may contain several layers, which are blitted sequentially to the screen. TileMap controls all of the layers functionality, so you don't need to worry about using this class directly.

Note:
The layer data is stored as an unidimensional array.

Public Member Functions

 MapLayer (int layer_width, int layer_height, int tile_width, int tile_height)
 Creates new layer.
int GetHeight ()
 Gets the layer height (in tiles).
RectGetScrollPos ()
 Gets the current scroll position.
Rect GetTileAtPos (Rect &pos)
 Returns tile coordinates at given position.
int GetTileIndex (unsigned int layer_position)
 Gets the tile stored in the given position.
int GetTileIndex (Rect &tile)
 Gets the tile stored in the given coordinates.
int GetWidth ()
 Gets the layer width (in tiles).
void Load (xml_node<> *node)
 Loads the layer from a xml tag.
void Scroll (int x, int y)
 Scrolls the layer.
void SetHeight (int height)
 Sets the layer height (in tiles).
void SetTileDimensions (int width, int height)
 Sets this layer's tile dimensions.
void SetTileIndex (int index, int x, int y)
 Sets a tile on this layer.
void SetWidth (int width)
 Sets the layer width (in tiles).

Constructor & Destructor Documentation

e2d::graphics::MapLayer::MapLayer ( int  layer_width,
int  layer_height,
int  tile_width,
int  tile_height 
)

If you don't want to load the map from a file, you may manually create a new layer using this constructor. All tile references will be 0 (zero).

Parameters:
layer_width width of this new layer
layer_height height of this new layer
tile_width width of the tiles on this new layer
tile_height height of the tiles on this new layer


Member Function Documentation

int e2d::graphics::MapLayer::GetHeight ( void   ) 

Returns:
Number of tiles in the Y axis for this layer.

Rect & e2d::graphics::MapLayer::GetScrollPos (  ) 

Gets the current scroll position for this layer. In the Rect, X and Y are the current tile, and W and H are the current pixel (offset) inside the tile.

Returns:
The scroll position of this layer.

Rect e2d::graphics::MapLayer::GetTileAtPos ( Rect pos  ) 

Given an absolute position in pixels, this method returns the tile coordinates for the tile that is under that position. The most upper-left tile has coordinates X=0 and Y=0.

Parameters:
pos The position you need to know what tile is there.
Returns:
a rect containing the coordinates of the tile in the layer.

int e2d::graphics::MapLayer::GetTileIndex ( unsigned int  layer_position  ) 

Assuming that each cell value in the layer data array is a reference to a tile index in a tileset, this method returns the tile index associated with this layer's position passed as a parameter.

Parameters:
layer_position Position of the layer from which you want the tile index.
Returns:
The tile index in the specified layer position.
Exceptions:
e2d::core::Exception if layer position is less than zero or greater than the number of tiles in this layer.

int e2d::graphics::MapLayer::GetTileIndex ( Rect tile  ) 

Same as above, but you can pass a tile's coordinates instead of a layer position.

Parameters:
tile Tile on this layer from which you want the tile index (you must set the rect's X and Y properties).
Returns:
The tile index of the specified tile.
Exceptions:
e2d::core::Exception if specified tile is outside the layer bounds.

int e2d::graphics::MapLayer::GetWidth ( void   ) 

Returns:
Number of tiles in the X axis for this layer.

void e2d::graphics::MapLayer::Load ( xml_node<> *  node  ) 

Reads the data from the <layer> tag of a map created with Tiled.

Parameters:
node parsed <layer> tag (xml_node is part of Rapid XML).
Exceptions:
e2d::core::Exception if node is either null or not a <layer> tag.

void e2d::graphics::MapLayer::Scroll ( int  x,
int  y 
)

Scrolling means that, whenever the layer is blitted, it will be blitted in a different position than the specified in the blitting method. Currently, only TileMap can blit a scrolled layer correctly. When you change the scroll position, TileMap::BlitLayer will blit it scrolled in relation to its viewport.

Parameters:
x Amount in pixels to scroll in the x axis
y Amount in pixels to scroll in the y axis

void e2d::graphics::MapLayer::SetHeight ( int  height  ) 

Sets this layer's height, in number of tiles. After loading a map with TileMap, the height is automatically set. If you change it after that, the map won't blit correctly.

Parameters:
height Number of tiles in the Y axis for this layer.

void e2d::graphics::MapLayer::SetTileDimensions ( int  width,
int  height 
)

Each layer is made of tiles, an all of them must have the same dimensions. With this method, you tell the layer what are the dimensions of the tiles it contains. After loading a map with TileMap, the dimensions are automatically set. If you change them after that, the map won't blit correctly.

Parameters:
width Width ot the tile.
height Height of the tile.

void e2d::graphics::MapLayer::SetTileIndex ( int  index,
int  x,
int  y 
)

If you want to change a tile on a layer, just call this method. The position is not a pixel positiion, but a tile position.

Parameters:
index the index of the tile
x the x position on this layer where the tile will be replaced
y the y position on this layer where the tile will be replaced

void e2d::graphics::MapLayer::SetWidth ( int  width  ) 

Sets this layer's width, in number of tiles. After loading a map with TileMap, the width is automatically set. If you change it after that, the map won't blit correctly.

Parameters:
width Number of tiles in the X axis for this layer.


Generated on Tue Dec 8 10:32:45 2009 for Easy2D by  doxygen 1.5.6