本文整理汇总了C++中CLayout::addChild方法的典型用法代码示例。如果您正苦于以下问题:C++ CLayout::addChild方法的具体用法?C++ CLayout::addChild怎么用?C++ CLayout::addChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CLayout
的用法示例。
在下文中一共展示了CLayout::addChild方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
bool CExpandableListViewBasicTest::init()
{
CExpandableListViewTestSceneBase::init();
setTitle("CExpandableListViewBasicTest");
setDescription("click item to expand");
pListView = CExpandableListView::create(CCSize(320, 390));
pListView->setBackgroundImage("background2.png");
pListView->setPosition(CCPoint(480, 320));
m_pWindow->addChild(pListView);
for( int i = 0; i < 10; i++ )
{
CExpandableNode* pExpandableNode = CExpandableNode::create();
pExpandableNode->setContentSize(CCSize(320, 50));
pListView->insertExpandableNodeAtLast(pExpandableNode);
CImageViewScale9* pExpandableNodeBg = CImageViewScale9::create(CCSize(320, 45), "expandnodebg.png");
pExpandableNodeBg->setPosition(CCPoint(320/2, 50/2));
pExpandableNode->addChild(pExpandableNodeBg);
CButton* pColBtn = CButton::createWith9Sprite(CCSize(35, 35), "sprite9_btn1.png", "sprite9_btn2.png");
pColBtn->setPosition(ccp(320 - 30, 50 / 2));
pColBtn->setText("-");
pColBtn->setUserTag(i);
pColBtn->setOnClickListener(this, ccw_click_selector(CExpandableListViewBasicTest::onClick));
pExpandableNode->addChild(pColBtn);
char buff[64] = {0};
sprintf(buff, "ExpandableNode : %d", i);
CLabel* pTitleLabel = CLabel::create(buff, "", 28);
pTitleLabel->setPosition(CCPoint(10, 50/2));
pTitleLabel->setAnchorPoint(CCPoint(0, 0.5));
pExpandableNode->addChild(pTitleLabel);
sprintf(buff, "Label %d - 1", i);
pExpandableNode->insertItemNodeAtLast(CLabel::create(buff, "", 30));
sprintf(buff, "Label %d - 2", i);
pExpandableNode->insertItemNodeAtLast(CLabel::create(buff, "", 30));
sprintf(buff, "Label %d - 3", i);
pExpandableNode->insertItemNodeAtLast(CLabel::create(buff, "", 30));
CButton* pButton = CButton::createWith9Sprite(CCSize(150, 38), "sprite9_btn1.png", "sprite9_btn2.png");
pButton->setOnClickListener(this, ccw_click_selector(CExpandableListViewBasicTest::onClick));
pButton->initText("collapse", "", 28);
pButton->setUserTag(i);
pButton->setPosition(CCPoint(100, 40/2));
CLayout* pBtnLayout = CLayout::create(CCSize(320, 40));
pBtnLayout->addChild(pButton);
pExpandableNode->insertItemNodeAtLast(pBtnLayout);
}
pListView->reloadData();
return true;
}
示例2: imageLoadSuccessCallBack
void CMainCityUI::imageLoadSuccessCallBack(string sTag, vector<char>* pBuffer)
{
CCImage* img = new CCImage;
img->initWithImageData((unsigned char*)pBuffer->data(), pBuffer->size());
CCTexture2D* texture = new CCTexture2D();
texture->initWithImage(img);
CLayout* headPart = (CLayout*)m_ui->findWidgetById("head_part");
CCSprite* head = (CCSprite*)headPart->getChildByTag(15);
// head->removeFromParent();
//head->setTexture(texture);
string path = HttpLoadImage::getInstance()->getStoragePath("download/fbImg",sTag.c_str())+".jpg";
string buff(pBuffer->begin(), pBuffer->end());
CCLOG("path: %s", path.c_str());
FILE *fp = fopen(path.c_str(), "wb+");
fwrite(buff.c_str(), 1, pBuffer->size(), fp);
fclose(fp);
// CCSprite *headbg = (CCSprite*)(m_ui->findWidgetById("headbg"));
// CCClippingNode *clip = CCClippingNode::create();
// CCSprite *fbimg = CCSprite::createWithTexture(texture);
// clip->addChild(fbimg);
//
// clip->setPosition(headbg->getPosition());
// clip->setContentSize(CCSizeMake(110,110));
//
// static ccColor4F red ={1,0,1};
// float radius = 106;
// const int nCount = 200;
// const float angle = 2.0f* (float)M_PI/nCount;
// CCPoint circle[nCount];
// for(int i=0; i<nCount; i++)
// {
// float radian = i*angle;
// circle[i].x = radius * cosf(radian);
// circle[i].y = radius * sinf(radian);
// }
// CCDrawNode *stencil= CCDrawNode::create();
// stencil->drawPolygon(circle,nCount,red,0,red);
// clip->setStencil(stencil);
// m_ui->addChild(clip);
CCSprite *headBg = (CCSprite *)(headPart->findWidgetById("headbg"));
CCSprite *headSpr = MakeFaceBookHeadToCircle(CCSprite::createWithTexture(texture));
headSpr->setTag(15);
headSpr->setPosition(headBg->getPosition());
headPart->addChild(headSpr);
head->removeFromParent();
img->release();
}
示例3: onEnter
void CVipCard::onEnter()
{
BaseLayer::onEnter();
//确定
CButton* pConfirm = (CButton*)m_ui->findWidgetById("confirm");
pConfirm->setOnClickListener(this, ccw_click_selector(CVipCard::onConfirm));
CButton* cancel = (CButton*)m_ui->findWidgetById("cancel");
cancel->setOnClickListener(this, ccw_click_selector(CVipCard::onCancel));
CButton* pClose = CButton::create("common/back.png", "common/back.png");
pClose->getSelectedImage()->setScale(1.1f);
pClose->setPosition(VLEFT+50, VTOP-50);
pClose->setOnClickListener(this,ccw_click_selector(CVipCard::onClose));
this->addChild(pClose, 999);
CImageViewScale9* pRect1 = (CImageViewScale9*)m_ui->findWidgetById("rect1");
m_cardText = CursorTextField::textFieldWithPlaceHolder("", FONT_NAME, 29, CCSize(690, 110), ccBLACK);
m_cardText->setPriority(this->getTouchPriority());
m_cardText->setLimitNum(17);
m_cardText->setAnchorPoint(ccp(0, 0.5f));
m_cardText->setPosition( ccp(pRect1->getPositionX()-440, pRect1->getPositionY()));
m_ui->addChild(m_cardText, 999);
//展示区图片
CLayout *pShowInfo = CLayout::create();
CScrollView *pScroll = (CScrollView*)m_ui->findWidgetById("scroll_info");
pScroll->setDirection(eScrollViewDirectionVertical);
pScroll->setBounceable(false);
pScroll->getContainer()->addChild(pShowInfo);
CCSize size = CCSize(957, 471);
pShowInfo->setContentSize(size);
pScroll->setContainerSize(size);
pShowInfo->setPosition(ccp(pScroll->getContainerSize().width*0.5f, pScroll->getContainerSize().height*0.5f));
pScroll->setContentOffsetToTop();
//嫁接内容
CLayout* pLayout = (CLayout*)findWidgetById("layer_info");
pLayout->retain();
pLayout->removeFromParent();
pShowInfo->addChild(pLayout);
pLayout->release();
pLayout->setPosition(ccp(size.width/2, size.height/2+10));
}
示例4: onClick
void CListViewOperateTest::onClick(Ref* pSender)
{
CButton* pButton = (CButton*) pSender;
switch(pButton->getUserTag())
{
case 1:
{
CLayout* pLayout = CLayout::create();
pLayout->setContentSize(Size(480, 30));
/*
CColorView* pColor = CColorView::create(Color4B(128, 0, 0, 255));
pColor->setContentSize(Size(478, 28));
pColor->setPosition(Point(480/2, 30/2));
pLayout->addChild(pColor);
*/
CButton* pButton = CButton::createWith9Sprite(Size(150, 25),
"sprite9_btn1.png", "sprite9_btn2.png");
pButton->setPosition(Vec2(480 /2, 30 /2));
char str[64] = {0};
sprintf(str, "%d", last_add_idx);
pButton->initText(str, "", 20);
pLayout->addChild(pButton);
last_add_idx++;
m_pListView->insertNodeAtLast(pLayout);
m_pListView->reloadData();
}
break;
case 2:
{
CLayout* pLayout = CLayout::create();
pLayout->setContentSize(Size(480, 30));
/*
CColorView* pColor = CColorView::create(Color4B(0, 128, 0, 255));
pColor->setContentSize(Size(478, 28));
pColor->setPosition(Point(480/2, 30/2));
pLayout->addChild(pColor);
*/
CButton* pButton = CButton::createWith9Sprite(Size(150, 25),
"sprite9_btn1.png", "sprite9_btn2.png");
pButton->setPosition(Vec2(480 /2, 30 /2));
char str[64] = {0};
sprintf(str, "%d", last_add_idx);
pButton->initText(str, "", 20);
pLayout->addChild(pButton);
last_add_idx++;
m_pListView->insertNodeAtFront(pLayout);
m_pListView->reloadData();
}
break;
case 3:
{
m_pListView->removeLastNode();
m_pListView->reloadData();
}
break;
case 4:
{
m_pListView->removeFrontNode();
m_pListView->reloadData();
}
break;
default:
break;
}
}
示例5: onEnter
void CMainCityUI::onEnter()
{
BaseLayer::onEnter();
UserData *user = DataCenter::sharedData()->getUser()->getUserData();
//角色信息相对位置处理
CLayout* headPart = (CLayout*)m_ui->findWidgetById("head_part");
headPart->setPosition(m_ui->convertToNodeSpace(ccp(VLEFT+headPart->getContentSize().width/2, VTOP-headPart->getContentSize().height/2)));
//显示角色名,等级,体力,金币
CLabel *nameLabel = (CLabel*)headPart->getChildByTag(10);
nameLabel->setString(user->getRoleName().c_str());
nameLabel->setColor(RGB_ROLE_COLOR);
CLabel *level = (CLabel*)(headPart->findWidgetById("level"));
level->setString(CCString::createWithFormat("Lv%d",user->getLevel())->getCString());
CProgressBar *progressBar = (CProgressBar*)(headPart->getChildByTag(11));
progressBar->setMaxValue(user->getNextExp());
progressBar->startProgress(user->getExp(),0.3f);
CLabelAtlas *vip_level = (CLabelAtlas*)(headPart->findWidgetById("level_vip"));
vip_level->setString(ToString(user->getVip()));
if (user->getVip()==0)
{
vip_level->setVisible(false);
CLabelAtlas *vip_font = (CLabelAtlas*)(headPart->findWidgetById("vip_font"));
vip_font->setVisible(false);
}
CImageView *headbg = (CImageView *)(headPart->findWidgetById("headbg"));
headbg->setTouchEnabled(true);
headbg->setOnClickListener(this, ccw_click_selector(CMainCityUI::onHeadImgBtn));
CButton *button = nullptr;
int i = 1;
for (; i<=9; ++i)
{
CCNode *lay = dynamic_cast<CCNode*>( m_ui->getChildByTag(i));
button = dynamic_cast<CButton*>(lay->getChildByTag(i));
// button->setEnabled(false);
button->setOnClickListener(this, ccw_click_selector(CMainCityUI::onClickBtn));
button->setSelectedTexture(((CCSprite*)(button->getNormalImage()))->getTexture());
button->getSelectedImage()->setScale(1.1f);
m_btnPos[i] = button->getPosition();
}
CCSprite* head = (CCSprite*)headPart->getChildByTag(15);
if (user->getThumb()>0)
{
CCTexture2D *texture = CCTextureCache::sharedTextureCache()
->addImage(CCString::createWithFormat("headIcon/%d.png", user->getThumb())->getCString());
if (texture)
{
head->setTexture(texture);
}
}
else
{
string fbName = user->getFbId()+".jpg";
string fullName = CCFileUtils::sharedFileUtils()->fullPathForFilename(fbName.c_str());
bool isFileExist = CCFileUtils::sharedFileUtils()->isFileExist(fullName);
if(isFileExist)
{
CCSprite *headBg = (CCSprite *)(headPart->findWidgetById("headbg"));
CCSprite *sp = CCSprite::create(fbName.c_str());
CCSprite* spr = MakeFaceBookHeadToCircle(sp);
spr->setPosition(headBg->getPosition());
headPart->removeChild(head);
spr->setTag(15);
headPart->addChild(spr);
}
else
{
HttpLoadImage::getInstance()->bindUiTarget(this);
CCString *imgUrl = CCString::createWithFormat(FACEBOOKIMG_106,user->getFbId().c_str());
HttpLoadImage::getInstance()->requestUrlImage(imgUrl->getCString(),user->getFbId().c_str());
}
}
CImageView* vip = (CImageView*)headPart->findWidgetById("vip");
vip->setTouchEnabled(true);
vip->setOnClickListener(this,ccw_click_selector(CMainCityUI::onVip));
//添加签到,充值等其他入口
CAccessLayer* pAccess = CAccessLayer::create();
this->addChild(pAccess, 99);
CSceneManager::sharedSceneManager()->addMsgObserver(UPDATE_HERO,this,GameMsghandler_selector(CMainCityUI::updateRoleProperty));
CSceneManager::sharedSceneManager()->addMsgObserver(TASK_NOTICE,this,GameMsghandler_selector(CMainCityUI::updateTaskNotice));
CSceneManager::sharedSceneManager()->addMsgObserver(MAIL_NOTICE,this,GameMsghandler_selector(CMainCityUI::updateMailNotice));
CSceneManager::sharedSceneManager()->addMsgObserver(UPDATE_FUNCTIONOPEN,this,GameMsghandler_selector(CMainCityUI::updateFuctionOpen));
CSceneManager::sharedSceneManager()->addMsgObserver(UPDATE_GAMETIP,this,GameMsghandler_selector(CMainCityUI::updateGameTip));
CSceneManager::sharedSceneManager()->addMsgObserver(SHOW_HEAD,this,GameMsghandler_selector(CMainCityUI::showHead));
CCSprite *red = (CCSprite*)(m_ui->findWidgetById("redPoint"));
CCSprite *mailPoint = (CCSprite*)(m_ui->findWidgetById("mailPoint"));
//.........这里部分代码省略.........
示例6: updateRoleProperty
void CMainCityUI::updateRoleProperty(const TMessage& tMsg)
{
UserData *user = DataCenter::sharedData()->getUser()->getUserData();
CLayout* headPart = (CLayout*)m_ui->findWidgetById("head_part");
CLabel *nameLabel = (CLabel*)headPart->getChildByTag(10);
nameLabel->setString(user->getRoleName().c_str());
CLabel *level = (CLabel*)(headPart->findWidgetById("level"));
level->setString(CCString::createWithFormat("Lv%d",user->getLevel())->getCString());
CLabelAtlas *vip = (CLabelAtlas*)(headPart->findWidgetById("level_vip"));
vip->setString(ToString(user->getVip()));
if (user->getVip()==0)
{
vip->setVisible(false);
CLabelAtlas *vip_font = (CLabelAtlas*)(headPart->findWidgetById("vip_font"));
vip_font->setVisible(false);
}
CCSprite* head = (CCSprite*)headPart->getChildByTag(15);
if (user->getThumb()>0)
{
// CCTexture2D *texture = CCTextureCache::sharedTextureCache()
// ->addImage(CCString::createWithFormat("headIcon/%d.png", user->getThumb())->getCString());
// if (texture)
// {
// head->setTexture(texture);
// }
// head->setFlipY(false);
CCSprite *headBg = (CCSprite *)(headPart->findWidgetById("headbg"));
CCString *strnName = CCString::createWithFormat("headIcon/%d.png", user->getThumb());
CCSprite *sp = CCSprite::create(strnName->getCString());
sp->setPosition(ccpAdd(headBg->getPosition(),ccp(0,10)));
sp->setScale(0.75f);
headPart->removeChild(head);
sp->setTag(15);
headPart->addChild(sp);
}
else
{
string fbName = user->getFbId()+".jpg";
string fullName = CCFileUtils::sharedFileUtils()->fullPathForFilename(fbName.c_str());
bool isFileExist = CCFileUtils::sharedFileUtils()->isFileExist(fullName);
if(isFileExist)
{
CCSprite *headBg = (CCSprite *)(headPart->findWidgetById("headbg"));
CCSprite *sp = CCSprite::create(fullName.c_str());
CCSprite* spr = MakeFaceBookHeadToCircle(sp);
spr->setPosition(headBg->getPosition());
headPart->removeChild(head);
spr->setTag(15);
headPart->addChild(spr);
}
else
{
HttpLoadImage::getInstance()->bindUiTarget(this);
CCString *imgUrl = CCString::createWithFormat(FACEBOOKIMG_106,user->getFbId().c_str());
HttpLoadImage::getInstance()->requestUrlImage(imgUrl->getCString(),user->getFbId().c_str());
}
}
CProgressBar *progressBar = (CProgressBar*)(headPart->getChildByTag(11));
progressBar->setMaxValue(user->getNextExp());
progressBar->startProgress(user->getExp(),0.3f);
}