How cocos2d-x2.2.3 reads Tiledmap maps
Directly add the code without explanation
# Include "TmxMapBasic. h "CCScene * TmxMapBasic: scene () {CCScene * s = CCScene: create (); TmxMapBasic * layer = TmxMapBasic: create (); s-> addChild (layer); return s;} bool TmxMapBasic: init () {LayerBack: init (); CCSize winSize = CCDirector: shareddire () -> getWinSize (); CCTMXTiledMap * map = CCTMXTiledMap: create ("orthogonal-test1.tmx"); addChild (map); // map-> setScaleX (winSize. width/map-> getContentSize (). width); // map-> setScaleY (winSize. height/map-> getContentSize (). height); setTouchEnabled (true); setTouchMode (kCCTouchesOneByOne); _ map = map; return true;} bool TmxMapBasic: ccTouchBegan (CCTouch * touch, CCEvent *) {CCPoint ptLocation = touch-> getLocation (); // ptLocation-> coordinate CCSize tileSize = _ map-> getTileSize () in the tmx map (); CCSize mapSize = _ map-> getMapSize (); CCPoint ptInMap; ptInMap. y = mapSize. height * tileSize. height-ptLocation. y; ptInMap. x = ptLocation. x; int tx = ptInMap. x/tileSize. width; int ty = ptInMap. y/tileSize. height; # if 0CCTMXLayer * layer0 = _ map-> layerNamed ("Layer 0"); layer0-> setTileGID (9, ccp (tx, ty )); CCSprite * sp = layer0-> tileAt (ccp (tx, ty); CCAction * action = CCJumpBy: create (3, ccp (0, 0), 30, 5 ); sp-> runAction (action); # endif // CCTMXLayer * layer1 = _ map-> layerNamed ("Layer 1"); // layer1-> setTileGID (9, ccp (tx, ty); # if 1CCTMXObjectGroup * objG = _ map-> objectGroupNamed ("OBJECT1"); CCArray * objs = objG-> getObjects (); int count = objs-> count (); // 5for (int I = 0; I <5; I ++) {CCObject * obj = objs-> objectAtIndex (I ); CCDictionary * dict = (CCDictionary *) obj; const CCString * x = dict-> valueForKey ("x"); const CCString * y = dict-> valueForKey ("y "); const CCString * height = dict-> valueForKey ("height"); CCLog ("x is % d, y is % d, h is % d ", x-> intValue (), y-> intValue (), height-> intValue ();} # endifreturn true ;}