Can't add Properties

Feb 7, 2011 at 3:16 PM

After I add custom properties then I can't get it in my code, plz tell me how i can do

Feb 7, 2011 at 3:32 PM
Edited Feb 7, 2011 at 3:39 PM

You should be able to access the properties via the Properties property accessor. Let's say you assigned a property named "Foo" with the value "Bar" at the map level, then you get the value of "Foo" as follows:

Map map = /* create or load map here... */
string fooProperty = map.Properties["Foo"];
// fooProperty should now contain "Bar"


The Properties property is defined in the abstract Component class from which the other components (Map, Layet, TileSet and Tile) are derived. Note also that the string accessor in Properties automatically casts to the four types: bool, int, float and string, so you don't need to do any explicit casting.

To programmatically assign a value to an existing property, do the following:

layer.Properties["Foo"] = 42; // assign integer 42 to existing property Foo

If the object does not have the required property, it will be created automatically and assigned the given value:

layer.Properties["Foo2"] = true; // assign new property Foo2 with boolean value True



Feb 8, 2011 at 2:12 PM
Edited Feb 8, 2011 at 2:14 PM

I tried it but a can get properties of map or Layer but properties of tilesheet I can't get, plz help me

Tile collision=layer.Tiles[x, y];

collision.Properties.Count alway = 0


Feb 8, 2011 at 3:39 PM

I set up a test scenario by placing a tile in the top-left corner of the top-most layer of the map file available in the demo (Map01.tide) and assigning the value 42 to a property called "Foo". I then accessed the variable using

int foo = m_map.Layers[3].Tiles[0, 0].Properties["Foo"];

After this statement, the variable foo contained the value 42.


Are you sure you are accessing the correct layer? If you're still unable to solve the issue, maybe you could set up a simple test project to reproduce the error and send it over so I can have a look at it.