Since v0.5 cocos2d for iPhone supports TileMaps. Instead of using the original cocos2d tilemap format (cocos2d for PC) it is using a new format based on the PGU tilemap editor.
This editor lets you edit tiles, tile maps and tile codes.
How do you install the PGU tilemap editor ?
- Mac OS/X 10.5 already has python 2.5 installed, but you need to install MacPython (the pygame installer needs it): python-2.5-macosx.dmg
- Once you have installed MacPython, you need to install pygame: pygame-1.8.1release-py2.5-macosx10.5.zip
- And once you have installed pygame, install pyobjc-1.4: http://www.pygame.org/ftp/pyobjc-1.4-py2.5-macosx10.4.mpkg.zip
- And then you can download and uncompress the PGU level editor: pgu_level_editor-20081118.tar.gz (This is the standard PGU dist + cocos2d examples)
To run the PGU level editor do:
home:~ $ cd src/pgu_level_editorhome:~/src/pgu_level_editor $ python leveledit.py level.tga
The left panel is the map.
The upper-right panel are the tiles.
The bottom-right panel are the codes.
The map is loaded from the file: level.tga
The tiles are loaded from the file: tiles.tga
The codes are loaded from the file: codes.tga
For more info see the leveledit.ini file. eg: you can change the tiles’ size.
Features and limitations:
- cocos2d v0.6.1 (an earlier) doesn’t support codes, so ignore this feature for the moment.
- PGU tile editor uses the TGA RGB channels to identify the codes, tiles’ positions and (mmm… what else? I’m not sure). So, you can only have 256 different tiles per TileMap.
IMPORTANT: You need to convert the tiles.tga file to PNG (eg: tiles.png). To convert a TGA file to PNG you can use the GIMP editor.
How to use these files from cocos2d for iPhone:
- Include the tiles.png and level.tga to your XCode project
- See the AtlasDemo example: TestAtlas.m. In particular see the Atlas3 demo.
-(id) init{if( ![super init] )return nil;
TileMapAtlas *tilemap = [TileMapAtlas tileMapAtlasWithTileFile:@"tiles.png" mapFile:@"level.tga" tileWidth:16 tileHeight:16];[self add:tilemap];
return self;}
Update: Added missing pyobjc-1.4 package

Recent Comments