CC_BREAK_IF (! CCLayer: init (); count = 0; _ tiled = CCTMXTiledMap: create ("tiled. tmx "); this-> addChild (_ tiled); // gets the hero's Object layer, then obtain the object CCTMXObjectGroup * object = _ tiled-> objectGroupNamed ("hero"); CCDictionary * spawnPoint = object-> objectNamed ("hero1") of a hero Based on the layer "); winsize = CCDirector: shareddire()-> getWinSize (); int px = spawnPoint-> valueForKey ("x")-> floatValue (); int py = spawnPoint-> valueForKey ("y")-> floatValue (); // CCLog ("x = % f, y = % f ", Px, py); _ player = CCSprite: create ("Player.png"); CC_BREAK_IF (! _ Player); _ player-> setAnchorPoint (CCPoint (); _ player-> setPosition (ccp (px, py); // obtain all enemy locations, create the enemy object = _ tiled-> objectGroupNamed ("enemy"); for (int I = 0; I
GetObjects ()-> count (); I ++) {CCDictionary * enemy = (CCDictionary *) object-> getObjects ()-> objectAtIndex (I ); if (enemy-> valueForKey ("n")-> intValue () = 1) {CCSprite * s = CCSprite: create ("enemy.png "); float x = enemy-> valueForKey ("x")-> floatValue (); float y = enemy-> valueForKey ("y")-> floatValue (); s-> setPosition (ccp (x, y); s-> setAnchorPoint (CCPoint (0, 0); _ tiled-> addChild (s, 4); CCActionInterval * move = CCMoveBy : Create (2, CCPoint (_ player-> getPosition (). x-s-> getPosition (). x> 0? 10:-10, _ player-> getPosition (). y-s-> getPosition (). y> 0? 10:-10); // CCFiniteTimeAction * func = CCCallFuncN: create (this, callfuncN_selector (HelloWorld: goon); s-> runAction (CCSequence :: create (move, func, NULL ));}}
Code: http://download.csdn.net/detail/five50/6829985