I’m doing a turn based tactics game, in the style of final fantasy tactics.
At the moment I’ve been working on passing a value from Tiled to indicate altitude.
My idea was to add a custom property to each tile in the tileset that would indicate how high a tile was, but I can’t find a way to pick a tile and then read tile properties from it.
An example of what I expect to work, and doesn’t:
battleMap.getLayer("ground").getTileAt(i, j).getProperty("Test");
or
battleMap.getLayer("ground").getTileAt(i, j).Test;
Any ideas? I can read custom properties from a object in an object layer, but that is an extra step I’d rather avoid.
ex:
battleMap.getObjectGroup("elevationObject").getObjects()[i].Test;
That will read whatever value I care to give it.
Funny thing tho, when I try to examine a tile through breakpoints in the variables tab, Cocos Code IDE hangs with a error message of “An internal error occurred during: “child count update”. java.lang.NullPointerException”.
IDE bugs a beyond my abilities, but maybe this has some bearing here.
I also make tactics games, so I know what you are talking about =)
The method you are looking for is:
CCDictionary* properties = _tileMap->propertiesForGID(tileGid);
That’s what i use in 2.2.6.
The I do things like check to see if that tile is a door:
if(properties->objectForKey(PROP_DOOR) != 0) dodoor();
That’s C++ code isn’t it? I’m using Javascript.
You did help though, I discovered that battleMap.getLayer(“ground”).getTileGIDAt(x,y) will return me the tile’s tileset id+1, which is enough to determine basically all of the tile’s properties, supposing I keep myself organized.
More poking around has revealed that my layer doesn’t have any tileset information attached to it at all. I really hope this doesn’t become a problem someday.
My mistake, sorry about the language mix up. I don’t know anything at all about the JS API, so please forgive me. I would assume, however, that the layer needs to know what tileset it is using to draw – that data would have to be in there somewhere.
On the off chance someone with this problem finds this, the code I was looking for is:
battleMap.getPropertiesForGID( battleMap.getLayer( "ground" ).getTileGIDAt( i,j ) )["Test"];
Here is a method I use
int STERegionMap::tgidProperty(unsigned int tileGid, const char* tmxProperty) {
CCDictionary* properties = _tileMap->propertiesForGID(tileGid);
if (properties && properties->objectForKey(tmxProperty) != 0) {
return ((CCString *)properties->objectForKey(tmxProperty))->intValue();
}
return -99;
}
My properties are assumed to be int value, or -99 for nothing. Works for me!