Tile maps (Tile map) are not only simple to generate, but also flexible for cocos2d-x engines. Whether your games are role-playing games, platform action games or imitation brick games, these game maps can be generated and saved in the TMX file format using the open source Tile Map editor Tiled map Editor, supported by Cocos2d-x. TMX Tile Map Format
COCOS2D supports map files (TMX) created by tiled. 2 versions of tiled:
The Java version is more stable and can be run on Mac OS X, Windows, and Linux.
The QT (native) version supports the functionality of most Java versions. When this help document is established, the latest QT version is 0.4.0 and supports all features except hexagonal maps (hexagonal maps).
Developers are free to choose between two different versions of tiled, and we recommend that you use the QT version developed by the tiled team to ensure you get the best support and updates. However, some developers still prefer to use the Java version of tiled because some features of the Java version are not yet fully ported to the QT version.
How to use the tiled tool to build a map with the Ray tutorial:
tile-based Game with Cocos2d
COCOS2D supports the following TMX maps: (Cocos2d supports the following TMX map form) Map orientation (orientation):
Orthogonal maps Rectangular bird's eye view map (90° map)
Isometric maps Isometric squint map (oblique 45° map)
Hexagonal Maps hexagon Map (the hexagonal map of the left or right or the upper and lower edges is not supported by tiled) (edges on left-right. Edges at Top-bottom are not supported ... it seems that T Iled doesn ' t support them either) map form (Tiles): Nested tile maps are not supported (such as using tile material groups with other pictures) only support the packaged tile Map group (only tile material groups are imported into the map file) Each layer supports up to 1 sets of tile material groups. map Layer (Layers): The number of layer in the tiles is not capped. Each layer can be represented by the Cctmxlayer class (for Ccspritesheet subclasses) each single tile is represented by Ccsprite (the parent node is Cctmxlayer) object Group (object Groups): Tile maps Support Object Group coordinates (coordinates) and global identities (Gids)
Coordinate
64*32 tiled tile Map File coordinate system is: (0,0): Upper left Corner (63,31): Lower right corner
Global Identity (Gids)
The GID of the tile is a global identifier, and his range begins with a positive integer 1, to the total number of tile in the tile map.
If your map has 5 different tiles, then: 0 of the GID is 1 tiles 1 of the GID is 2 tiles 3 of the GID is 3 and so on
The 0 GID of the tile is used to indicate that the tile is empty.
How to establish a TMX node
Create a TMX map
cctmxtiledmap *map = cctmxtiledmap::create ("tilemaps/iso-test-vertexz.tmx");
AddChild (map, 0, ktagtilemap);
The tiles by default would be aliased. If you are want to create anti-alias tiles, your should do:
//Iterate the "layers" (Atlas Sprite Managers)
// and set them as ' AntiAlias '
ccarray * pchildrenarray = Map->getchildren ();
ccspritebatchnode* child = NULL;
ccobject* pobject = NULL;
Ccarray_foreach (Pchildrenarray, pobject)
{Child
= (ccspritebatchnode*) pobject;
if (!child) break
;
Child->gettexture ()->setantialiastexparameters ();
How to get/Add/remove/Modify a tile
Specify coordinates to obtain tile: