<map version="0.99b" orientation="orthogonal" width="30" height="30" tilewidth="32" tileheight="32"> <tileset ...> ... </tileset> <layer name="Layer 0" width="30" height="30"> <data encoding="base64" compression="gzip"> H4sn+/809NTECxAOAAA= </data> </layer> </map>
In tag <map>, version is the version of Tiled (Easy2D doesn't read it); orientation is the type of map (currently only "orthogonal" is supported); width and height are the size of map, in number of tiles; tilewidth and tileheight are the dimensions in pixels of each tile. The <tileset> tag must follow the format described in the Tileset class.
Then comes the <layer> tag; you can have as many of these you want, each of them representing a layer of this map. Attribute name is not read; width and height are the layer size, in number of tiles. In tag <data>, attribute encoding tells the encoding type for the layer data: currently only "base64" is supported (no unencoded layer data allowed). compression is optional, an tells what kind of compression (if any) is used on the layer data (only "gzip" allowed). The contents of the tag represents the layer data.
To blit the map, you must blit its layers one by one. This makes possible to blit other graphical elements (say, sprites) in between the layers. You may also choose a portion of the entire map that will be blitted when a call to BlitLayer() is made. This portion is called "viewport", and is represented by this map's attributes X, Y, W and H. At the moment the map is loaded (via Load), if the video has already been initialized via Video::Init, then the viewport is automatically set to the framebuffer's dimensions. Otherwise, it is set to the full map size. The viewport's X and Y dictates the position of the destination surface where the map shall be blitted, and W and H are its dimensions. Note that no tile will be blitted cut, so you may expect the layer to do not fit the viewport precisely (some tiles will overflow the boundaries). This is a normal behaviour of the blitting technique Easy2D applies.
Public Member Functions | |
TileMap (const TileMap &original) | |
Copy constructor. | |
int | AddLayer (MapLayer *layer) |
Adds a layer to this map. | |
int | AddTileset (Tileset *tileset) |
Adds a tileset to this map. | |
void | BlitLayer (unsigned int num_layer, SDL_Surface *destination) |
Blits one of the map layers. | |
MapLayer * | GetLayer (int num_layer) |
Gets a pointer to one of this map's layers. | |
int | GetNumberOfLayers (void) |
Returns the number of layers assigned to this map. | |
int | GetNumberOfTilesets (void) |
Returns the number of tilesets assigned to this map. | |
Tileset * | GetTileset (int num_tileset) |
Gets a pointer to one of this map's tilesets. | |
string | GetTileProperty (int num_layer, Rect &tile, string property) |
Retrieves a property from a tile in a layer. | |
int | GetTileHeight (void) |
Gets this map's tile height. | |
int | GetTileWidth (void) |
Gets this map's tile width. | |
void | Load (const char *filename) |
Loads a tile map made with Tiled. | |
void | Optimize (void) |
Optimizes blitting. | |
void | Scroll (int x, int y) |
Scrolls the entire map. | |
void | ScrollLayer (int num_layer, int x, int y) |
Scrolls the selected layer. |
e2d::graphics::TileMap::TileMap | ( | const TileMap & | original | ) |
Creates a copy of another tilemap.
original | The original tilemap to copy data from. |
int e2d::graphics::TileMap::AddLayer | ( | MapLayer * | layer | ) |
Adds a layer to this map.
layer | New layer. |
e2d::core::Exception | if layer is NULL. |
int e2d::graphics::TileMap::AddTileset | ( | Tileset * | tileset | ) |
Adds a tileset to this map.
tileset | New tileset. |
e2d::core::Exception | if tileset is NULL. |
void e2d::graphics::TileMap::BlitLayer | ( | unsigned int | num_layer, | |
SDL_Surface * | destination | |||
) |
Blits a single layer to some surface.
num_layer | Index of layer to be blitted | |
destination | Pointer to an SDL_Surface where the layer will be blitted |
e2d::core::Exception | if num_layer is greater than the number of layers in this map. |
MapLayer * e2d::graphics::TileMap::GetLayer | ( | int | num_layer | ) |
If you want to get a layer, that's the way you do it.
num_layer | Index of layer you want to get. |
int e2d::graphics::TileMap::GetNumberOfLayers | ( | void | ) |
int e2d::graphics::TileMap::GetNumberOfTilesets | ( | void | ) |
Tileset * e2d::graphics::TileMap::GetTileset | ( | int | num_tileset | ) |
If you want to get a tileset, that's the way you do it.
num_tileset | Index of tileset you want to get. |
string e2d::graphics::TileMap::GetTileProperty | ( | int | num_layer, | |
Rect & | tile, | |||
string | property | |||
) |
Calls Tileset::GetProperty for the selected tile.
num_layer | Index of layer where the desired tile is | |
tile | Coordinates of the tile you want to take the property | |
property | Name of the property from which you want the value |
int e2d::graphics::TileMap::GetTileHeight | ( | void | ) |
int e2d::graphics::TileMap::GetTileWidth | ( | void | ) |
void e2d::graphics::TileMap::Load | ( | const char * | filename | ) |
Loads a tile map in *.tmx format, made with Tiled (www.mapeditor.org).
filename | Path for the *.tmx map file |
e2d::core::Exception | if any parsing error occurs. |
void e2d::graphics::TileMap::Optimize | ( | void | ) |
Calls Tileset::Optimize on all of this map's tilesets.
void e2d::graphics::TileMap::Scroll | ( | int | x, | |
int | y | |||
) |
Calls MapLayer::Scroll on all layers.
x | Amount in pixels to scroll in the x axis | |
y | Amount in pixels to scroll in the y axis |
void e2d::graphics::TileMap::ScrollLayer | ( | int | num_layer, | |
int | x, | |||
int | y | |||
) |
Calls MapLayer::Scroll on the selected layer.
num_layer | Index of layer to be scrolled | |
x | Amount in pixels to scroll in the x axis | |
y | Amount in pixels to scroll in the y axis |