e2d::graphics::TileMap Class Reference

Inheritance diagram for e2d::graphics::TileMap:


List of all members.

Detailed Description

Easy2D is able to load tile maps made with a nice editor called Tiled (www.mapeditor.org). Tiled exports the maps in xml format (named *.tmx), and Easy2D can read them. The xml format must be as follows:

  <map version="0.99b" orientation="orthogonal" width="30" height="30"
       tilewidth="32" tileheight="32">
    <tileset ...>
    <layer name="Layer 0" width="30" height="30">
      <data encoding="base64" compression="gzip">

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.

If you load a map using a xml file, its tileset will be automatically added to (or recovered from) the ResourceMap.

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.
MapLayerGetLayer (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.
TilesetGetTileset (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.

Constructor & Destructor Documentation

e2d::graphics::TileMap::TileMap ( const TileMap original  ) 

Creates a copy of another tilemap.

original The original tilemap to copy data from.

Member Function Documentation

int e2d::graphics::TileMap::AddLayer ( MapLayer layer  ) 

Adds a layer to this map.

layer New layer.
index of the newly added layer.
e2d::core::Exception if layer is NULL.

int e2d::graphics::TileMap::AddTileset ( Tileset tileset  ) 

Adds a tileset to this map.

tileset New tileset.
index of the newly added 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.
a layer

int e2d::graphics::TileMap::GetNumberOfLayers ( void   ) 

number of layers assigned to this map

int e2d::graphics::TileMap::GetNumberOfTilesets ( void   ) 

number of tilesets assigned to this map

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.
a tileset

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
Value of the named property for the given tile on the given layer.

int e2d::graphics::TileMap::GetTileHeight ( void   ) 

The tile height defined for this map

int e2d::graphics::TileMap::GetTileWidth ( void   ) 

The tile width defined for this map

void e2d::graphics::TileMap::Load ( const char *  filename  ) 

Loads a tile map in *.tmx format, made with Tiled (www.mapeditor.org).

The tmx file makes a reference to an image file (the tileset), make sure that the path for this image file is correct.
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

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