Game Development Reference
In-Depth Information
-(id) init
if ((self = [super init]))
CCTMXTiledMap* tileMap = [CCTMXTiledMap tiledMapWithTMXFile:@"orthogonal.tmx"];
[self addChild:tileMap z:-1 tag:TileMapNode];
CCTMXLayer* eventLayer = [tileMap layerNamed:@"GameEventLayer"];
eventLayer.visible = NO;
self.isTouchEnabled = YES;
return self;
The CCTMXTiledMap class is initialized with the name of the TMX file and then ad-
ded as a child with a tag so that it can be retrieved later. An instance variable would of
course work just as well. The next step is to retrieve the CCTMXTiledMap used for
game events by using the layerNamed method and providing the name of the layer
as it was named in Tiled. Because the game events layer will be used only as hints for
code to determine properties of certain tiles, this layer shouldn't be rendered at all.
Note that if you uncheck the layer in Tiled, it won't be displayed, but you won't have
access to its tiles and tile properties either.
If you run the project now, you'll see a tilemap just like in Figure 10-10 .
Search Nedrilad ::

Custom Search