Game Development Reference
In-Depth Information
The CCTMXTiledMap has a propertiesForGID method, which returns an
NSDictionary if there are properties available for the tile with the given idenjpgier
(GID). This NSDictionary contains the properties edited in Tiled (see Figure 10-8
). The dictionary stores any key/value pairs as NSString objects. To see what's in a
particular NSDictionary for debugging purposes, you can use a CCLOG statement
like this:
CCLOG(@"NSDictionary 'properties' contains:\n%@", properties);
This will print out a line similar to the following in the Debugger Console window:
2010-08-30 19:50:52.344 Tilemap[978:207] NSDictionary 'properties' contains:
isWater = 1;
You'll be dealing with a variety of NSDictionary objects while working with
tilemaps. Logging its contents allows you to peek inside any NSDictionary , or any
iPhone SDK collection class, for that matter. This will frequently come in handy.
You can retrieve each property in an NSDictionary by its name through the
NSDictionary method valueForKey , which returns an NSString . To get a
Bool value from the NSString , you can simply use the NSString 's boolValue
property. In much the same way, you can retrieve integer and floating-point values us-
ing NSString 's intValue and floatValue properties, respectively.
At the end of ccTouchesBegan , I check whether the touch was on water, and if so,
a sound is played. Otherwise, I retrieve the WinterLayer and toggle its visible
property by negating it. Changing seasons has never been this simple! The effect
should illustrate how you can use multiple layers in Tiled to achieve changes on a glob-
al scale without having to load a completely separate tilemap.
For more local changes to individual tiles, you can use the removeTileAt and
setTileGID methods to remove or replace tiles of a specific layer during game play:
[winterLayer removeTileAt:tilePos];
[winterLayer setTileGID:tileGID at:tilePos];
Search Nedrilad ::

Custom Search