-
Notifications
You must be signed in to change notification settings - Fork 87
TmxList
TmxList is a KeyedCollection which stores lists of the principal
TiledSharp objects (Tilesets, Layers,
ObjectGroups, Objects). 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.Tilesets["trees"];
trees = map.Tilesets[2];
The Tiled map editor does not enforce unique names for layers, tilesets or
objects. If two TmxList items have the same name, then TiledSharp appends a
counter to the names of the duplicates. For example, if the name "myLayer"
appears three times in a TMX file, then the corresponding TiledSharp names (or
keys) are "myLayer"
, "myLayer1"
, and "myLayer2"
.
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.Layers["water"];
bushes = map.Layers["bushes"];
trees = map.Layers["trees"];
bushes1 = map.Layers["bushes1"];
bushes2 = map.Layers["bushes2"];
or by index
water = map.Layers[0];
bushes = map.Layers[1];
trees = map.Layers[2];
bushes1 = map.Layers[3];
bushes2 = map.Layers[4];
The most pathological case occurs when the label name already exists as a separate entry, such as bushes
, bushes
, and bushes1
. These are resolved by inserting successive underscores between the name and the distinguishing index. For example, if bushes
and bushes1
exist, then successive bushes
entries will be bushes_1
, bushes__1
, and so on. But the actual rules are difficult to summarize. Duplicate label names are best avoided if at all possible.