Wasn't really sure if I should drag up this old topic or start a new one, but I've completely rewritten this class. I decided to post here to make sure the original author gets credit for his work which started the whole thing in the first place. I've written a post about it
here which includes a download with some examples but for brevity here's the readme:
This class is designed to load TILED .tmx format maps, compatible with
TILED up to version 0.9.0
http://trederia.blogspot.co.uk/2013/05/tiled-map-loader-for-sfml.html
What's Supported
----------------
Uses pugixml (included) to parse xml
Supports orthogonal maps
Supports isometric maps
Supports conversion between orthogonal and isometric world coords
Parses all types of layers (normal, object and image), layer properties
Parses all type of object, object shapes, types, properties
Option to draw debug output of objects, grid and object names
Supports multiple tile sets, including tsx files
Supports all layer encoding and compression: base64, csv, zlib, gzip and xml (requires zlib library, see /lib directory)
What's not supported / limitations
----------------------------------
Parsing of individual tile properties
Flipping / rotation of sprites
Staggered isometric maps
Tile set images must be in the same directory as tmx/tsx files
To display object names when drawing object debug shapes then you must provide a font
and update MapObject.h
Usage
-----
To quickly get up and running create an instance of the MapLoader class
tmx::MapLoader ml("path/to/maps");
load a map file
ml.Load("map.tmx");
and draw it in your main loop
ml.Draw(renderTarget);
Note that the constructor takes a path to the directory containing the map files as a parameter (with
or without the trailing '/') so that you only need pass the map name to MapLoader::Load(). Currently
all map files (tmx, tsx, images etc) must be in the diretory passed to the constructor.
New maps can be loaded simply by calling the load function again, existing maps will be automatically
unloaded. MapLoader::Load() also returns true on success and false on failure, to aid running the function
in its own thread for example. Conversion functions are provided for converting coordinate spaces between
orthogonal and isometric. For instance MapLoader::OthogonalToIsometric will convert mouse coordinates from
screen space:
0--------X
|
|
|
|
|
Y
to Isometric space:
0
/ \
/ \
/ \
/ \
Y X
Layer information can be accessed through MapLoader::GetLayers()
bool collision;
for(auto layer = ml.GetLayers().begin(); layer != ml.GetLayers().end(); ++layer)
{
if(layer->name == "Collision")
{
for(auto object = layer->objects.begin(); object != layer->objects.end(); ++object)
{
collision = object->Contains(point);
}
}
}
For more detailed examples see the source for the demos.
Requirements
------------
pugixml (included)
zlib (http://zlib.net/)
SFML 2.0 (http://sfml-dev.org)
as well as being a rewrite, it contains quite a few enhancements / new features.
This may be a stupid question but SetDrawingBounds does that limit the tilemap to only be drawn on those specific sections of the tilemap itself or with regards to how it is drawn on the screen?
SetDrawingBounds is used to define which tiles are visible, to save drawing tiles which don't need to be drawn. In the new version it is called automatically by Draw using the view of the supplied renderTarget.