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). | |
Rect & | GetScrollPos () |
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). |
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).
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 |
int e2d::graphics::MapLayer::GetHeight | ( | void | ) |
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.
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.
pos | The position you need to know what tile is there. |
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.
layer_position | Position of the layer from which you want the tile index. |
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.
tile | Tile on this layer from which you want the tile index (you must set the rect's X and Y properties). |
e2d::core::Exception | if specified tile is outside the layer bounds. |
int e2d::graphics::MapLayer::GetWidth | ( | void | ) |
void e2d::graphics::MapLayer::Load | ( | xml_node<> * | node | ) |
Reads the data from the <layer> tag of a map created with Tiled.
node | parsed <layer> tag (xml_node is part of Rapid XML). |
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.
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.
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.
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.
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.
width | Number of tiles in the X axis for this layer. |