bool HelloWorld::init() { if ( !CCLayer::init() ) { return false; } //创建一个节点 CCNode *anode = CCNode::create(); //将节点作为子节点增加场景类中 this->addChild(anode,0); CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuCloseCallback) ); pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) ); CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); pMenu->setPosition( CCPointZero ); //将菜单作为子节点增加之前定义的节点中 anode->addChild(pMenu, 1); CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Thonburi", 34); CCSize size = CCDirector::sharedDirector()->getWinSize(); pLabel->setPosition( ccp(size.width / 2, size.height - 20) ); //将标签作为子节点增加之前定义的节点中 anode->addChild(pLabel, 1); CCSprite* pSprite = CCSprite::create("HelloWorld.png"); pSprite->setPosition( ccp(size.width/2, size.height/2) ); //将背景图片作为子节点增加之前定义的节点中 anode->addChild(pSprite, 0); return true;}
Cocos2D-x权威指南:通过节点控制屏幕中的全体渲染对象,布布扣,bubuko.com
Cocos2D-x权威指南:通过节点控制屏幕中的全体渲染对象
原文地址:http://www.cnblogs.com/mfrbuaa/p/3770186.html