Game Development Reference
ating it through the Browse button in the Resources folder of the Tilemap01 project.
If you check the “Use transparent color” check box, transparent areas will simply be
drawn in pink (the default color). You can leave this box unchecked for now because
the tiles in use have no transparent areas.
The tile width and height are the dimensions of individual tiles in the tileset. They
should match the tile size of 32 × 32 pixels, which you set when creating the new map.
The Margin and Spacing settings determine how many pixels away from the image
border the tiles are and how many pixels of space are between them. In the case of the
dg_grounds32.png , there's no spacing at all, so I set both values to 0.
If you had your tiles aligned by TexturePacker to create a tileset texture, you must enter
the pixel-padding value used by TexturePacker in the Margin and Spacing fields. By
default, TexturePacker uses a padding of 0 pixels.
When loading a new tileset image, make sure the tileset image is already located in
your project's Resource folder. You should then also make sure to save the tilemap
TMX file to the same folder where the tileset image used by the tilemap is located.
Otherwise, cocos2d might fail to load the tileset image; trying to load the TMX file
will then cause a runtime exception. The culprit is that TMX files reference the tileset
image relative to the location the TMX file is saved to. If they're not both in the same
folder, cocos2d may be unable to find the image because the folder structure isn't pre-
served when the app is installed in the simulator or on the device.
TIP TMX files are plain XML files, so you might want to peek inside if you're
curious. If you see the image file referenced with parts of a path, then cocos2d
is unlikely to load the referenced image file. The image reference should list
just the image filename without any path components, like so: <image
source = "tiles.png"/> .
How to create Tilemaps for Retina and iPad Resolutions
Tiled has no concept of varying resolutions for tilemaps. But cocos2d supports all the
usual extensions like -hd , -ipad and -ipadhd for tilemap files. Problem is, how to
convert an existing tilemap to an HD tilemap or vice versa?