Today I learned the basics of map in Cocos2D-x and learned how maps are going in the game. From this section I will re-write an example.
Open door, map editor we use open source software: tiled-0.9.1-win32-setup.exe, can be directly downloaded on the Internet, the map editing method is very simple, you can find on the Internet, here I just record some key points in my code:
So let's see the Code directly (the map file we generated using the map editor is level01.tmx );
CCTMXTiledMap * map = CCTMXTiledMap: create ("level01.tmx"); this-> addChild (map); AddPlayer (map); CCSize size = CCDirector: shareddire () -> getWinSize (); CCSprite * sprite = CCSprite: create ("player.png"); Player * player = Player: create (); player-> BindSprite (sprite ); map-> addChild (player); CCTMXObjectGroup * objgroup = map-> objectGroupNamed ("player"); CCDictionary * playerpoint = objgroup-> objectNamed ("playerpoint "); float x = playerpoint-> valueForKey ("x")-> floatValue (); float y = playerpoint-> valueForKey ("y")-> floatValue (); player-> setPosition (ccp (x, y ));
Final effect: