bool HelloWorld::init(){ if ( !cclayer::init() ) { return false; } CCSize winSize = CCDirector::sharedDirector()->getWinSize(); // (position)位置和(anchorpoint)锚点,这两个东西必定是重合的,首先是根据setposition设置好在父节点的位置,锚点再根据位置进行重合旋转 CCSprite *pSpr = CCSprite::create("Icon-57.png"); pSpr->setposition(ccp(winSize.wIDth/2.0,winSize.height/2.0)); pSpr->setAnchorPoint(ccp(0.5,0.5)); this->addChild(pSpr); cclabelTTF *pPositonTTF = cclabelTTF::create("","Arial",20); pPositonTTF->setposition(ccp(winSize.wIDth/2.0,winSize.height/2.0/2.0)); this->addChild(pPositonTTF); cclabelTTF *pAnchorPointTTF = cclabelTTF::create("",20); pAnchorPointTTF->setposition(ccp(winSize.wIDth/2.0,winSize.height/2.0/2.0-30)); this->addChild(pAnchorPointTTF); CCPoint position = pSpr->getposition(); CCString *strposition = CCString::createWithFormat("position: x:%.1f,y:%.1f",position.x,position.y); pPositonTTF->setString(strposition->getCString()); CCPoint anchor = pSpr->getAnchorPoint(); CCString *strAnchor = CCString::createWithFormat("AnchorPoint: x:%.1f,anchor.x,anchor.y); pAnchorPointTTF->setString(strAnchor->getCString()); return true;}
效果图如下:
总结
以上是内存溢出为你收集整理的Cocos2d-x_位置和锚点全部内容,希望文章能够帮你解决Cocos2d-x_位置和锚点所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)