Skip to content

TiledSharp Class Overview

marshallward edited this page Apr 5, 2012 · 13 revisions

This is an overview of the classes and data types used by TiledSharp.

Principal classes

Map is an abstraction of a TMX file and its associated data. It contains basic information about the map, such as the map size (in tiles) or the tile size (in pixels). It also contains the principal TMX data elements (Tileset, Layer, MapObjectGroup, MapObject), which are organized into TiledLists.

Tileset objects contain data associated with tile appearance. Each tileset contains a reference to an image, which can be decomposed into a selection of individual tiles. The image reference can be either the name of an embedded resource or an explicit file path.

Layer objects describe the tile map as a list, where each element contains a global tile ID for each grid point. The order is sequential, rather than as a two-dimensional array, although each element also stores its own coordinates.

MapObjectGroup objects contain information about the Tiled "object layers". Object groups allow for organization of objects into separate layers.

MapObject objects contain detailed information about the various Tiled objects (Locations, Tiles, Polygons, Polylines). MapObject positions are in pixels, rather than tile position, since they are not constrained by the tile grid.

Supplemental classes and structures

TiledList is a KeyedCollection which stores lists of the principal TiledSharp classes. TiledLists are accessible by either their names or by index. For example, if the tileset with name "trees" is the third TMX tileset, then it can be accessed by either of the following instructions:

trees = map.tileset["trees"];
trees = map.tileset[2];

Duplicate entries

The Tiled map editor does not enforce unique names for layers, tilesets or objects. If two TiledList items have the same name, the second is appended with a counter. If the name "myLayer" appears three times in the TMX file, then the TiledSharp names (or keys) are "myLayer", "myLayer 1", and "myLayer 2".

For a more specific example, consider a TMX file containing the following layers:

<layer name="water">
<layer name="bushes">
<layer name="trees">
<layer name="bushes">
<layer name="bushes">

then the layer data can be accessed by name or by index:

  water = map.layer["water"];
 bushes = map.layer["bushes"];
  trees = map.layer["trees"];
bushes1 = map.layer["bushes 1"];
bushes2 = map.layer["bushes 2"];

or by index

  water = map.layer[0];
 bushes = map.layer[1];
  trees = map.layer[2];
bushes1 = map.layer[3];
bushes2 = map.layer[4];
Clone this wiki locally