Game Development Reference
In-Depth Information
NSDictionary* properties = [tileMap propertiesForGID:tileGID];
if (properties)
NSString* isWaterProperty = [properties valueForKey:@"isWater"];
isTouchOnWater = isWaterProperty.boolValue;
// Decide what to do depending on where the touch was
if (isTouchOnWater)
[[SimpleAudioEngine sharedEngine] playEffect:@"alien-sfx.caf"];
// Get the winter layer and toggle its visibility
CCTMXLayer* winterLayer = [tileMap layerNamed:@"WinterLayer"];
winterLayer.visible = !winterLayer.visible;
The CCTMXTiledMap is retrieved as usual. The location of the touch is first conver-
ted into screen coordinates and then used to retrieve the tilePos containing the in-
dices into the tilemap at that specific screen location. I'll get to the
tilePosFromLocation method in a minute. For now, just know that it returns the
index of the touched tile.
At this point, I have to introduce the concept of global idenjpgiers (GIDs) for tiles,
which are unique integer numbers assigned to each tile used in a tilemap. The tiles in a
map are consecutively numbered, starting with 1. A GID of 0 represents an empty tile.
With the tileGIDAt method of the CCTMXLayer , you can determine the GID num-
ber of the tile at the given tile coordinates.
Next, the CCTMXLayer named GameEventLayer is obtained from the tilemap.
This is the layer where I defined the isWater tile and drew it over the river tiles. The
tileGIDAt method returns the unique idenjpgier for this tile. If the idenjpgier hap-
pens to be 0, it means there is no tile at this position on this layer—in that case, it's
already clear that the touched tile can't be an isWater tile.
Search Nedrilad ::

Custom Search