创建元素,四要素。
第一点,定义。
一般是在头文件里面定义。
第二点,创建。
主要是和相应资源绑定。
第三点,设置位置。
自己的需要。
第四点,添加。
添加到场景才能显示。
示例:精灵的创建
CCSprite *pSprite;
pSprite = CCSprite::create("资源的相应路径");
pSprite->setPosition(ccp(x坐标,y坐标));
this->addChild(pSprite,层数);
按钮的创建
///<再来一次按钮>
CCMenuItemImage *pAgain;///<按钮的图片>
CCMenu *pMenu;///<按钮>
pAgain = CCMenuItemImage::create(
"U3/PartB/Game/Frog/result/button1.png",
"U3/PartB/Game/Frog/result/button2.png",
this,
menu_selector(U3BGameScene::menuClick));
pAgain->setPosition(ccp(650, 220));
pAgain->setTag(9999);
pMenu = CCMenu::create(pAgain, NULL);
pMenu->setPosition(CCPointZero);
addChild(pMenu,6);
cocos2d-x文本框的创建
1、直接贴文字
CCLabelTTF的创建(略)
2、从相应图片上读取文字显示,相当于截取的图片文字
CCLabelAtlas的创建
CCLabelAtlas pLabel_time;
pLabel_time=CCLabelAtlas::create(game_time,"U3/PartB/Game/Frog/result/number.png",20,29, '0');
pLabel_time->setPosition( ccp(357, 700) );
this->addChild(pLabel_time,3);
CCLabelBMFont的创建
CCLabelBMFont label_all;
label_all = CCLabelBMFont::create("string", "U3/PartB/Game/Frog/font/word.fnt");
this->addChild(label_all);
label_all->setPosition(ccp(420, 606));
label_all->setString(title[vRand[0]]);