Reputation: 18149
Using cocos2d-iphone and Tiled (Mac version) for creating .tmx maps.
I have an object layer with a couple objects in it.
Within the game, I need to access the X and Y position of such objects. I managed to access their property list alright, but apparently I can't get the X, Y, Width or Height at all. Ideas?
Upvotes: 1
Views: 587
Reputation: 64477
From your CCTMXTiledMap you get the object group like this:
CCTMXObjectGroup* objectGroup = [tileMap objectGroupNamed:@"myObjects"];
You can then iterate over the objects
NSMutableArray or get a specific object:
NSMutableDictionary* dict = [objectGroup objectNamed:@"someObject"];
An object is simply a dictionary that holds all the properties of the object. You can access x, y, width, height, name and type simply by using these keywords as the keys for the dictionary.
NSNumber* numberForX = [dict objectForKey:@"x"];
int x = [numberForX intValue];
Upvotes: 3