Friday, 15 March 2013

ios - Using Tileset Image Properties in a Cocos2d TMXTiledMap -



ios - Using Tileset Image Properties in a Cocos2d TMXTiledMap -

i'm working on ios game uses cocos2d tmxtiledmap read isometric maps produced in tiled application.

in tiled can add together properties each image in tileset (ie. images displayed in lower right corner of screen)

it makes sense me utilize these properties help determine whether or not tile type traversable game character.

for instance, if tile 3,5 using image of grass land-based characters can walk there.

conversely, if tile 4,8 using image of water land-based characters cannot walk there.

i had hoped accomplish creating property on grass , water tiles called terrain_type 0 land , 1 water. (i had hoped) access tile 3,5 @ runtime , somehow know tile 3,5 used grass image property of terrain_type=0

now, realize there other techniques available accomplish same thing (object layers come mind) seems best way go it. when add together multiple tile layers , want know tile 3,5 has both grass , wall on it.

my questions: possible? , how go it. or, misunderstanding how tiled , tmxtiledmap supposed work?

much appreciated...

amazing. spent lot of time trying work before posted question and, of course, figured out few hours later. key utilize cctmxmapinfo class.

anyway, here's solution since think useful others:

in tiled application create map has tile layer named "bottom" add property each tile image in section called "tilesets" (bottom right corner) right clicking on each image , selecting "tile properties" name property "terrain_type" , set value whatever (e.g. terrain_type = 0 land or terrain_type = 1 water) use these images paint tilemap , save

use code read properties single tile @ location 3,5:

//read tile map tmxtiledmap *tilemap = [cctmxtiledmap tiledmapwithtmxfile:@"sample_map.tmx"]; //get bottom layer tilemap cctmxlayer *bottomlayer = [tilemap layernamed:@"bottom"]; //get cctmxmapinfo object -- tmxtiledmap not contain tile image properties cctmxmapinfo * mapinfo = [cctmxmapinfo formatwithtmxfile: @"sample_map.tmx"]; //get tile id of tile image used @ coordinate (3, 5) in layer int tileid = [bottomlayer tilegidat: ccp(3, 5)]; //get properties tile image nsdictionary *properties = [mapinfo.tileproperties objectforkey:[nsnumber numberwithint:tileid] ]; //get terrain_type property nsstring *terraintype = [properties objectforkey:@"terrain_type"];

ios cocos2d-iphone

No comments:

Post a Comment