本文整理汇总了C++中CCLayer::addChild方法的典型用法代码示例。如果您正苦于以下问题:C++ CCLayer::addChild方法的具体用法?C++ CCLayer::addChild怎么用?C++ CCLayer::addChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCLayer
的用法示例。
在下文中一共展示了CCLayer::addChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateLayerMessageBox
void AssetsUpdateLayer::updateLayerMessageBox()
{
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("ccb/ccbResources/SystemLoading.plist");
CCLayer* layer = CCLayer::create();
layer->ignoreAnchorPointForPosition(false);
layer->setContentSize(Size(960, 640));
layer->setPosition(Point(Director::getInstance()->getWinSize().width * 0.5, Director::getInstance()->getWinSize().height * 0.5));
layer->setScale(Director::getInstance()->getWinSize().width / 960);
addChild(layer, 1);
Sprite* messageboxSprite = Sprite::createWithSpriteFrameName("set_floor_v1.png");
messageboxSprite->setPosition(Point(480, 320));
layer->addChild(messageboxSprite, 1);
LabelTTF* labelContent = LabelTTF::create(Localization::getInstance()->getValueByKey("Loading_warning_need_update"), "Helvetica",32);
labelContent->setPosition(Point(480, 420));
layer->addChild(labelContent, 1);
ControlButton* btn = ControlButton::create(LabelTTF::create(Localization::getInstance()->getValueByKey("BUTTON_DONE"), "Helvetica", 32), Scale9Sprite::createWithSpriteFrameName("set_button2.png"));
btn->setPreferredSize(CCSize(191,70));
btn->setPosition(Point(480, 220));
btn->addTargetWithActionForControlEvents(this, cccontrol_selector(AssetsUpdateLayer::GoToAppPage), Control::EventType::TOUCH_UP_INSIDE);
layer->addChild(btn, 1);
}
示例2: showTimerBoarder
CCLayer* GameScene::showTimerBoarder()
{
CCLayer* board = CCLayer::create();
CCSprite* boardBG = CCSprite::create("header.png");
boardBG->setPosition(ccp(320,0));
boardBG->setAnchorPoint(ccp(0.5f,0));
board->addChild(boardBG);
CCMenuItemImage* imageItem = CCMenuItemImage::create("btn-pause.png","btn-pause-down.png", this,menu_selector(GameScene::restartScene));
imageItem->setAnchorPoint(ccp(0,1));
CCMenu* menu = CCMenu::create(imageItem,NULL);
menu->setAnchorPoint(ccp(0,1));
menu->setPosition(ccp(0,158));
pr = CCProgressTimer::create(CCSprite::create("timer.png"));
pr->setPosition(ccp(320,16));
pr->setAnchorPoint(ccp(0.5,0));
pr->setPercentage(1.0f);
pr->setType(kCCProgressTimerTypeBar);
pr->setMidpoint(ccp(1,0));
pr->setBarChangeRate(ccp(1,0));
this->schedule(schedule_selector(GameScene::countTime),1.0f);
scoreTxt = CCLabelBMFont::create("0","fonts/scorefont.fnt");
scoreTxt->setAnchorPoint(ccp(1,0.5f));
scoreTxt->setScale(1.0f);
scoreTxt->setAlignment(kCCTextAlignmentRight);
scoreTxt->setPosition(ccp(640,110));
board->addChild(scoreTxt,10);
board->addChild(pr);
board->addChild(menu);
return board;
}
示例3: CCPointMake
//------------------------------------------------------------------
//
// StressTest2
//
//------------------------------------------------------------------
StressTest2::StressTest2()
{
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCLayer* sublayer = CCLayer::node();
CCSprite *sp1 = CCSprite::spriteWithFile(s_pPathSister1);
sp1->setPosition( CCPointMake(80, s.height/2) );
CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(350,0));
CCActionInterval* move_ease_inout3 = CCEaseInOut::actionWithAction((CCActionInterval*)(move->copy()->autorelease()), 2.0f);
CCActionInterval* move_ease_inout_back3 = move_ease_inout3->reverse();
CCFiniteTimeAction* seq3 = CCSequence::actions( move_ease_inout3, move_ease_inout_back3, NULL);
sp1->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)seq3) );
sublayer->addChild(sp1, 1);
CCParticleFire* fire = CCParticleFire::node();
fire->setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/fire.png"));
fire->setPosition( CCPointMake(80, s.height/2-50) );
CCActionInterval* copy_seq3 = (CCActionInterval*)(seq3->copy()->autorelease());
fire->runAction( CCRepeatForever::actionWithAction(copy_seq3) );
sublayer->addChild(fire, 2);
schedule(schedule_selector(StressTest2::shouldNotLeak), 6.0f);
addChild(sublayer, 0, kTagSprite1);
}
示例4: showGameEnd
void GameScene::showGameEnd()
{
gameLayer->showGameEnd();
timeBoard->runAction(CCMoveTo::create(0.3f,ccp(0,1136+158)));
CCLayer* gameEndLayer = CCLayer::create();
CCSprite* bgSprite = CCSprite::create("fade.png");
scoreTxt = CCLabelBMFont::create(GameData::shareData()->getScoreString(),"fonts/scorefont.fnt");
scoreTxt->setPosition(ccp(320,700));
scoreTxt->setScale(0.0f);
CCScaleTo* scaleTo = CCScaleTo::create(0.9f,2.5f);
CCEaseElasticInOut* scoreEff = CCEaseElasticInOut::create(scaleTo);
scoreTxt->runAction(scoreEff);
if(!scoreTxt->getParent())
gameEndLayer->addChild(scoreTxt);
bgSprite->setAnchorPoint(ccp(0,0));
gameEndLayer->addChild(bgSprite);
CCLabelTTF* txt = CCLabelTTF::create("Game End","fonts/Marker Felt.ttf",40.0f);
txt->setPosition(ccp(320,568));
gameEndLayer->addChild(txt);
CCMenuItemImage* imageItem = CCMenuItemImage::create("CloseNormal.png","CLoseSelected.png", this,menu_selector(GameScene::backToMainMenu));
CCMenu* menu = CCMenu::create(imageItem,NULL);
menu->setAnchorPoint(ccp(0,0));
menu->setPosition(ccp(320,300));
imageItem->setScale(3.0f);
gameEndLayer->addChild(menu);
this->addChild(gameEndLayer,100,this->getChildrenCount());
}
示例5: setTipLayer
void HelpScene::setTipLayer(CCLayer* tipLayer){
CCSprite* bottom = SPRITE(bottom.png);
bottom->setPosition(ccp(VisibleRect::bottom().x,VisibleRect::bottom().y+35));
tipLayer->addChild(bottom);
GiantPageScrollView* tipsScrollView = GiantPageScrollView::create();
tipsScrollView->setPosition(VisibleRect::center());
tipsScrollView->cellSize = CCDirector::sharedDirector()->getWinSize();
tipsScrollView->tableSize = CCDirector::sharedDirector()->getWinSize();
tipsScrollView->cellNum = 4;
tipsScrollView->cells = CCArray::createWithCapacity(4);
for(int i=0;i<4;i++){
CCLayer* tipItem = CCLayer::create();
CCString* sprName = CCString::createWithFormat("tips_%d.png",i+1);
CCString* tipName = CCString::createWithFormat("tips_text_%d_CN.png",i+1);
CCSprite* tipStr = CCSprite::createWithSpriteFrameName(tipName->getCString());
CCSprite* tip = CCSprite::createWithSpriteFrameName(sprName->getCString());
tip->setPosition(VisibleRect::center());
tipStr->setPosition(ccp(VisibleRect::center().x,VisibleRect::center().y-200));
tipItem->ignoreAnchorPointForPosition(false);
tipItem->setPosition(VisibleRect::center());
tipItem->addChild(tip);
tipItem->addChild(tipStr);
tipsScrollView->cells->addObject(tipItem);
}
tipsScrollView->cells->retain();
tipLayer->addChild(tipsScrollView);
}
示例6: myInit
void ThirdServerScene::myInit() {
CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("bgm_server.mp3",true);
cacheServerId = CCUserDefault::sharedUserDefault()->getIntegerForKey("serverId",-1);
loginTrigger = LoginTrigger::create(this);
loginTrigger->retain();
MyMessageManage::getInstance()->registerTrigger(loginTrigger);
CCLayer* backLayer = CCLayer::create();
CCSprite* background = CCSprite::create("loading.jpg");
// background->setScale(winSize.height/background->getContentSize().height);
background->setAnchorPoint(ccp(0.5,0));
background->setPositionX(winSize.width/2);
backLayer->addChild(background);
CCSprite* logo = CCSprite::create("logo.png");
logo->setPosition(ccp(winSize.width-190,winSize.height-120));
backLayer->addChild(logo,2);
CCSprite* shadow = CCSprite::createWithSpriteFrameName("serverShadow.png");
shadow->setScale((winSize.height+10)/shadow->getContentSize().height);
shadow->setPosition(ccp(winSize.width-138,winSize.height/2));
backLayer->addChild(shadow);
CCSprite* listLabel = CCSprite::createWithSpriteFrameName("serverListLabel.png");
listLabel->setAnchorPoint(ccp(0,1));
listLabel->setPosition(ccp(winSize.width-270,100));
backLayer->addChild(listLabel,1);
if (beans->count() == 0) {
this->addChild(MyUtil::getInstance()->getServerTipDialog("连接服务器失败,\n请检测网络!",this,menu_selector(ServerScene::exitGame)),5);
return;
}
SeverInfoBean* bean = NULL;
CCObject* obj;
CCARRAY_FOREACH(beans,obj) {
if (cacheServerId == ((SeverInfoBean*)obj)->serverId) {
bean = (SeverInfoBean*)obj;
break;
}
}
if (bean == NULL) {
bean =(SeverInfoBean*) beans->objectAtIndex(beans->count()-1);
}
initServerInfo(bean);
this->addChild(backLayer);
}
示例7: createHelpLayer
void GameLayer::createHelpLayer() {
CCLayer *layer = CCLayer::create();
CCSprite *left = CCSprite::create("help_left.png");
left->setAnchorPoint(ccp(0.5, 0));
left->setPosition(ccpp(-0.33, -0.345));
CCSprite *right = CCSprite::create("help_right.png");
right->setAnchorPoint(ccp(0.5, 0));
right->setPosition(ccpp(0.33, -0.345));
layer->addChild(left);
layer->addChild(right);
this->addChild(layer, 0, TAG_LAYER_HELP);
}
示例8: MainMenu
bool Scene1Welcome::init(){
if(!CCScene::init()){
return false;
}
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCSprite* pBg = CCSprite::create("[email protected]");
pBg->setPosition(ccp(size.width/2, size.height/2));
CCLayer* layerBtns = CCLayer::create();
this->addChild(pBg);
this->addChild(layerBtns);
CCSprite* pLogo = CCSprite::create("logo.png");
pLogo->setAnchorPoint(ccp(0.5, 1));
pLogo->setPosition(ccp(size.width/2, size.height-150));
layerBtns->addChild(pLogo);
CCSprite* spriteBtnPlay = CCSprite::create("btn_play.png");
CCSprite* spriteBtnPlaySelected = CCSprite::create("btn_play_selected.png");
CCMenuItemSprite* menuBtnPlay = CCMenuItemSprite::create(spriteBtnPlay,
spriteBtnPlaySelected,
this,
menu_selector(Scene1Welcome::onBtnPlayClick));
menuBtnPlay->setPosition(ccp(0.5, 1));
menuBtnPlay->setPosition(ccp(size.width/2, size.height-420));
//CCLog("%f", size.height);
MainMenu* mainMenu = new MainMenu();
//layerBtns->addChild(pBtnPlay);
//layerBtns->addChild(spriteBtnMain);
CCMenu* pMenu = CCMenu::create(menuBtnPlay, NULL);
pMenu->setPosition(CCPointZero);
layerBtns->addChild(pMenu);
//layerBtns->addChild(mainMenu->pMenu);
//mainMenu->showWithAnimate();
//CCActionInterval* actionInterval = CCActionInterval::create(5);
//CCEaseBackInOut* easeBackInOut = CCEaseBackInOut::create(actionInterval);
//pLogo->runAction(easeBackInOut);
return true;
}
示例9: getPrizeInfo
CCLayer* LevelQuest::getPrizeInfo() {
CCLayer* prizeLayer = CCLayer::create();
for (int i=0; i<prizeResourceTagList->count(); i++) {
int prizeTag = ((GXintValue*)prizeResourceTagList->objectAtIndex(i))->getValue();
int prizeCount = ((GXintValue*)prizeResourceCountList->objectAtIndex(i))->getValue();
CCSprite* icon1 = MyUtil::getInstance()->getResourceIcon(prizeTag);
icon1->setScale(Mathlib::min(40/icon1->getContentSize().width,40/icon1->getContentSize().height));
icon1->setPosition(ccp(430,307-50*i));
CCSprite* sprite1 = CCSprite::createWithSpriteFrameName("questLight.png");
sprite1->setScale(1.15);
sprite1->setOpacity(200);
sprite1->setPosition(ccp(430,307-50*i));
char str[30] = {0};
sprintf(str,"%d",prizeCount);
CCLabelAtlas* count1 = CCLabelAtlas::create(str, "number7.png", 24, 36, '/');
count1->setPosition(ccp(603.5,307-50*i));
count1->setScale(0.6);
count1->setColor(ccc3(230, 207, 185));
count1->setAnchorPoint(ccp(1,0.5));
CCSprite* dividingLine1 = CCSprite::createWithSpriteFrameName("uiDialogCommonLine.png");
dividingLine1->setScaleX(190/dividingLine1->getContentSize().width);
dividingLine1->setPosition(ccp(508.5,295-50*i));
dividingLine1->setScaleY(2/dividingLine1->getContentSize().height);
CCSprite* dividingLine2 = CCSprite::createWithSpriteFrameName("uiDialogCommonLine.png");
dividingLine2->setScaleX(80/dividingLine2->getContentSize().width);
dividingLine2->setScaleY(2/dividingLine2->getContentSize().height);
dividingLine2->setAnchorPoint(ccp(1,0.5));
dividingLine2->setPosition(ccp(603,290-50*i));
prizeLayer->addChild(dividingLine1);
prizeLayer->addChild(dividingLine2);
prizeLayer->addChild(sprite1);
prizeLayer->addChild(icon1);
prizeLayer->addChild(count1);
}
return prizeLayer;
}
示例10: getPrizeInfo
CCLayer* PowerQuest::getPrizeInfo() {
CCLayer* prizeLayer = CCLayer::create();
// CCSprite* icon1 = MyUtil::getInstance()->getResourceIcon(prizeTag);
// icon1->setScale(Mathlib::min(40/icon1->getContentSize().width,40/icon1->getContentSize().height));
CCSprite* icon1 = CCSprite::createWithSpriteFrameName("powerIcon.png");
icon1->setScale(Mathlib::min(40/icon1->getContentSize().width,40/icon1->getContentSize().height));
icon1->setPosition(ccp(430,307));
CCSprite* sprite1 = CCSprite::createWithSpriteFrameName("questLight.png");
sprite1->setScale(1.15);
sprite1->setOpacity(200);
sprite1->setPosition(ccp(430,307));
char str[30] = {0};
sprintf(str,"%d",(int)prizePower->getValue());
CCLabelAtlas* count1 = CCLabelAtlas::create(str, "number7.png", 24, 36, '/');
count1->setPosition(ccp(603.5,307));
count1->setScale(0.6);
count1->setColor(ccc3(230, 207, 185));
count1->setAnchorPoint(ccp(1,0.5));
CCSprite* dividingLine1 = CCSprite::createWithSpriteFrameName("uiDialogCommonLine.png");
dividingLine1->setScaleX(190/dividingLine1->getContentSize().width);
dividingLine1->setPosition(ccp(508.5,295));
dividingLine1->setScaleY(2/dividingLine1->getContentSize().height);
CCSprite* dividingLine2 = CCSprite::createWithSpriteFrameName("uiDialogCommonLine.png");
dividingLine2->setScaleX(80/dividingLine2->getContentSize().width);
dividingLine2->setScaleY(2/dividingLine2->getContentSize().height);
dividingLine2->setAnchorPoint(ccp(1,0.5));
dividingLine2->setPosition(ccp(603,290));
prizeLayer->addChild(dividingLine1);
prizeLayer->addChild(dividingLine2);
prizeLayer->addChild(sprite1);
prizeLayer->addChild(icon1);
prizeLayer->addChild(count1);
return prizeLayer;
}
示例11: if
void Newbie1Trigger::toNextCallBack(cocos2d::CCNode *pSender) {
if (statues == 0) {
node->removeChildByTag(newbieFlowLayerTag,true);
CCLayer* newbieLayer = CCLayer::create();
CCSprite* gray = CCSprite::create("whiteImage.jpg");
gray->setPosition(ccp(winSize.width/2,winSize.height/2));
gray->setScaleX(winSize.width/gray->getContentSize().width);
gray->setScaleY(winSize.height/gray->getContentSize().height);
gray->setColor(ccc3(0,0,0));
gray->setOpacity(0);
gray->runAction(CCFadeTo::create(0.5,150));
newbieLayer->addChild(gray);
CCString* str = GXUtil::readFile("NewbieDialog1.j");
node->addChild(DiaLayer::create(GXJsonUtil::parseDiaLayerInfoBean(str->getCString())),11);
newbieLayer->setTag(newbieFlowLayerTag);
node->addChild(newbieLayer);
MyMenuItem* sprite = MyMenuItem::create(CCSprite::create("skipTutorials.png"),this,menu_selector(Newbie1Trigger::toSkip));
sprite->setPosition(ccp(winSize.width-200,550));
MyPriorityMenu* skipMenu = MyPriorityMenu::create(-601,sprite,NULL);
skipMenu->setPosition(ccp(0,0));
skipMenu->setTag(skipMenuLayerTag);
node->addChild(skipMenu);
statues++;
} else if(statues == 1) {
Newbie1to2Message::create()->sendMsg();
}
// CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("sfx_click.mp3");
}
示例12: resetPos
void GiftListView::resetPos()
{
for (int i=0;i<(int)mPages.count();i++)
removeChild((CCNode*)mPages.objectAtIndex(i),true);
mPages.removeAllObjects();
mPageTotal=0;
for (int i=0;i<(int)mGiftItems.count();i++)
((CCNode*)mGiftItems.objectAtIndex(i))->removeFromParentAndCleanup(true);
for (int i=0;i<(int)mGiftItems.count();i++)
{
CCNode* item = (CCNode*)mGiftItems.objectAtIndex(i);
int page = ceil((double)(i+1) / mPageSize);//放到第几页
int posid = i % mPageSize;//这页第几个
if (page>mPageTotal) // 如果大于当前页数了,增加一页面
addPage();
CCLayer* curpage = (CCLayer*)mPages.objectAtIndex(mPageTotal-1);//最后一页
int col = posid%mPageRowSize;//第几列
int row = (int)(posid/mPageRowSize)+1;//第几行
float itemW = item->getContentSize().width;
float itemH = item->getContentSize().height;
float itemX = col*(itemW+mItemIntervalH);
float itemY = getContentSize().height - (row*(itemH+mItemIntervalV));
item->setPosition(ccp(itemX,itemY));
curpage->addChild(item);
}
}
示例13: initSceneLayer
void SceneRender::initSceneLayer(const char* filename)
{
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
/////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the program
// you may modify it.
// add a "close" icon to exit the progress. it's an autorelease object
pCloseItem = CCMenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(SceneRender::menuCloseCallback));
pCloseItem->setPosition(ccp(visibleSize.width - 70 , 50));
// pCloseItem->setScale(2.0);
// create menu, it's an autorelease object
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu, 1);
CCLayer* pLayer = CCLayer::create();
this->addChild(pLayer);
pScene = SceneReader::sharedSceneReader()->createNodeWithSceneFile(filename);
pLayer->addChild(pScene);
aa = ActionManager::shareManager()->playActionByName("startMenu_1.json", "Animation1");
sendEvent(TRIGGEREVENT_INITSCENE);
this->schedule(schedule_selector(SceneRender::gameLogic));
this->setTouchEnabled(true);
this->setTouchMode(kCCTouchesOneByOne);
}
示例14: init
bool LevelScene::init()
{
bool bRet = false;
do {
CC_BREAK_IF( !CCLayer::init() );
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCLayer* layer = CCLayer::create();
for (int i =0; i<5 ; i++)
{
CCString* str = CCString::createWithFormat("%d.png",i+1);
CCSprite* spr = CCSprite::create(str->getCString());
spr->setPosition(ccpAdd(ccp(size.width/2, size.height/2), ccp(size.width*i, 0)));
layer->addChild(spr);
}
m_scrollView = CCScrollView::create(size);
m_scrollView->setContainer(layer);
m_scrollView->setTouchEnabled(false);
m_scrollView->setContentOffset(CCPoint(0, 0));
this->addChild(m_scrollView);
this->setTouchEnabled(true);
m_nCurPage = 0;
bRet = true;
} while (0);
return bRet;
}
示例15: addNewSever
void FrontCoverLayer::addNewSever()
{
UILayout* m_layout = UIManager::sharedManager()->getUILayout("SplashLayout");
if(m_severScrollPage)
{
CCLayer* layer = CCLayer::create();
m_severScrollPage->addPage(layer);
int count = m_severList.size();
int currentPage = 0;
int column = 3;
int row = 2;
ASprite *as = AspriteManager::getInstance()->getAsprite(KUI_BIN);
int idx = map_ui_FRAME_SELECTSERVE_BUTTON;
int selectedId = map_ui_FRAME_SELECTSERVE_BUTTON_CLICKED;
float scale = UIManager::sharedManager()->getScaleFactor();
float width = m_severScrollPage->getContentSize().width / scale;
float height = m_severScrollPage->getContentSize().height / scale;
CCRect rect = as->getframeRect(idx);
float deltaWidth = (width - column * rect.size.width )/(column + 1);
float deltaHeigth = (height - row * rect.size.height )/(row + 1);
for(int i =0; i< count; i++)
{
int index = i;
int page = index / (column * row);
int rowIndex = (index - page * column * row) / column;
int columnIndex = (index - page * column * row) % column;
if(page != currentPage)
{
currentPage = page;
CCLayer* newlayer = CCLayer::create();
m_severScrollPage->addPage(newlayer);
}
CCPoint pt;
CCSprite *pEmptyItem = as->getSpriteFromFrame_Middle( idx, 0, pt);
CCSprite *pSelectedItem = as->getSpriteFromFrame_Middle(selectedId ,0,pt);
IconButton * pIcon = new IconButton(pEmptyItem, NULL, pSelectedItem, this,
menu_selector(FrontCoverLayer::onClickedOneSever));
pIcon->autorelease();
pIcon->SetButtonIndex(index);
pIcon->setContentSize(pEmptyItem->getContentSize());
float x = -width * 0.5f + deltaWidth * (columnIndex + 1) + (columnIndex + 0.5f) * rect.size.width ;
float y = height * 0.5f - (rowIndex + 0.5f) * (deltaHeigth + rect.size.height );
pIcon->setPosition(ccp(x, y));
UILabelTTF* label = UILabelTTF::create(m_severList[i]->name,KJLinXin,40,pEmptyItem->getContentSize(),kCCTextAlignmentCenter,kCCVerticalTextAlignmentCenter);
pIcon->addChild(label);
m_lstButton.push_back(pIcon);
CCLayer* currentLayer = m_severScrollPage->getPageLayer(currentPage);
currentLayer->addChild(pIcon,index);
}
}
}