Question

After making my TMX based map in Tiled, I would like to programatically change certain properties of the tiles as my game progresses.

This is the code I've tried but it doesn't work. But I include it here to demonstrate the logic of what I'm trying to achieve...

NSDictionary *currentProperties = [_tileMap propertiesForGID:tileToMarkFalling];
[currentProperties[@"Falling"] setString:@"True"];
[_tileMap propertiesForGID:tileToMarkFalling] = currentProperties;

The error thrown here is "Expression is not assignable".

How can I set these properties programatically, thanks.

Was it helpful?

Solution

The last line is not proper syntax, you can't assign a value to (the result of) a selector/message/function call. In fact cocos2d stores the TMX properties as immutable dictionary unfortunately, you can't modify them. You'll have to get the properties and store them yourself in your own class in a mutable dictionary or other way.

Note that the dictionary is not the ideal way to store logic info for tiles, if you check each tile's properties dict for "falling" and possibly other values every frame the dictionary lookup overhead will cost you performance, possibly quite severely if you have thousands of tiles.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top