本文主要是介绍cocos2d中在titled中创建对象层及获取坐标,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
通过titled插入对象层objects:
通过矩形框画出一个矩形:
设置其属性名称为PlayerPoint:
设计一个addplayer函数代码:
<span style="font-size:18px;"> auto visibileSize=Director::sharedDirector()->getVisibleSize();//获取窗口大小auto playerSprite=Sprite::create("run1.png");auto mPlayer=Player::create();mPlayer->bindSprite(playerSprite);</span><span style="font-size:18px;">//绑定精灵</span>
<span style="font-size:18px;">TMXObjectGroup* objGroup=map->objectGroupNamed("objects");auto playerPointDic=objGroup->objectNamed("PlayerPoint");float playerX=playerPointDic["x"].asFloat();float playerY=playerPointDic["y"].asFloat();mPlayer->setPosition(ccp(playerX,playerY));map->addChild(mPlayer);</span>
这篇关于cocos2d中在titled中创建对象层及获取坐标的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!