关于cocos2dx 对tiled地图编辑器的使用
来源:未知 责任编辑:责任编辑 发表时间:2014-01-20 07:52 点击:次
CC_BREAK_IF(! CCLayer::init()); count=0; _tiled=CCTMXTiledMap::create("tiled.tmx"); this->addChild(_tiled); //获取英雄的对象层,再根据层获取某英雄的对象 CCTMXObjectGroup *object =_tiled->objectGroupNamed("hero"); CCDictionary *spawnPoint=object->objectNamed("hero1"); winsize =CCDirector::sharedDirector()->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(0,0)); _player->setPosition(ccp(px,py)); //获取所有敌人位置,再其中创建敌人 object=_tiled->objectGroupNamed("enemy"); for(int i=0;igetObjects()->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)); } }
代码下载地址 :http://download.csdn.net/detail/five50/6829985
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>