Reprinted! Please indicate the source when reprint: http://blog.csdn.net/aa4790139/article/details/8132740
In the previous article, we talked about scenario switching. This is naturally the production of the game interface. Game map creation:
1. cctilemapatlas:
//Create a cctilemapatlas:
Cctilemapatlas * map = cctilemapatlas: create(map material .png, map data. TGA .., tile block width, tile block height );
Cocos2dx is retained for compatibility. Currently, cocos2dx does not recommend this method for puzzles...
2. cctmxtiledmap
//Create a cctmxtiledmap (first loading method)
Cctmxtiledmap * map = cctmxtiledmap: Create ("tilemaps/orthogonal-test5.tmx ");
Addchild (MAP, 0, ktagtilemap );
//Create a cctmxtiledmap (method 2)
String resources = "tilemaps ";
String file = resources + "/orthogonal-test1.tmx ";
Ccstring * STR = ccstring: createwithcontentsoffile (ccfileutils: sharedfileutils ()-> fullpathfromrelativepath (file. c_str ()));
// Create parameter description: full path of the resource file, resource path directory
Cctmxtiledmap * map = cctmxtiledmap: Create (STR-> getcstring (), resources. c_str ());
//Update hierarchies, The underlying layer will be re-ordered
Map-> reorderchild (m_tamara, newzorder );
//Obtain layer objects by name
Cctmxlayer * layer = map-> layernamed ("Trees ");
//The corresponding genie can be obtained based on the location of the genie in the layer.
M_tamara = Layer-> tileat (CCP (0, 11 ));
//You can set the top-level to achieve the blocking effect. The level is inverted. 0 indicates the top-level.
M_tamara-> setvertexz (-1 );
//Set camera position
Float x, y, z;
Map-> getcamera ()-> geteyexyz (& X, & Y, & Z );
Map-> getcamera ()-> seteyexyz (x-200, Y, Z + 300 );
//Set Animation
Map-> runaction (ccscaleby: Create (2, 0.5f ));
//First, remove the genie (S. Width-1, 0) from the layer.
Ccsprite * sprite = Layer-> tileat (CCP (S. Width-1, 0 ));
Layer-> removechild (sprite, true );
// Second, remove the (5, 0) sprite from the layer.
Layer-> removetileat (CCP (5, 0 ));
//Obtain the object group based on the group name:
Cctmxobjectgroup * Group = map-> objectgroupnamed ("object group name ");
//Obtain all objects in the group
Ccarray * objects = group-> getobjects ();
//Set tile at a location of Map
// Set the opposite side of the (x, y) object. If yes, remove it. The complement map element gid = Block 1 does not exist. 1 indicates the tileeditor graph block. The first tile in
Layer-> settilegid (1, CCP (x, y ));
//Set the tile to move up or down:
The following is a piece of code introduced in test. I don't know much about it. If you have any details, please let me know. Thank you!
// () Position tile, control to update tileccpoint tilecoord = CCP (); int flags; unsigned int gid = Layer-> tilegidat (tilecoord, (cctmxtileflags *) in the vertical direction *) & flags); If (flags & kcctmxtileverticalflag) flags & = ~ Kcctmxtileverticalflag; else flags | = kcctmxtileverticalflag; // tilelayer-> settilegid (GID, tilecoord, (cctmxtileflags) flags) are updated in two locations );
Thank you for reading my blog and hope you can see your footprints!
If something is wrong or incorrect,I also hope you can point it out!