本文整理汇总了C++中CCLayerColor::addChild方法的典型用法代码示例。如果您正苦于以下问题:C++ CCLayerColor::addChild方法的具体用法?C++ CCLayerColor::addChild怎么用?C++ CCLayerColor::addChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCLayerColor
的用法示例。
在下文中一共展示了CCLayerColor::addChild方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ccp
//创建一个对应的简单的button,代表具体的章
CCLayerColor *SGSpecialBattleLayer::createChapButton(int buttonTag, SpecialBattleData *data)
{
CCLayerColor *layerColor = CCLayerColor::create(ccc4(0, 255, 0, 0), 160, 160);
layerColor->setTag(111);
layerColor->setAnchorPoint(ccp(0.5, 0.5));
if (data)
{
CCSprite *headIcon = SGDrawCards::createPureSprite(data->itemId, data->itemType, sg_specialBattleLayer);
CCSprite *borderIcon = CCSprite::createWithSpriteFrameName("equipPinzhi_5_0.png");
headIcon->addChild(borderIcon, 1);
borderIcon->setPosition(ccpAdd(ccp(headIcon->getContentSize().width / 2, headIcon->getContentSize().height / 2), ccp(0, 0)));
CCSprite *headIcon1 = SGDrawCards::createPureSprite(data->itemId, data->itemType, sg_specialBattleLayer);
CCSprite *borderIcon1 = CCSprite::createWithSpriteFrameName("equipPinzhi_5_0.png");
headIcon1->addChild(borderIcon1, 1);
borderIcon1->setPosition(ccpAdd(ccp(headIcon1->getContentSize().width / 2, headIcon1->getContentSize().height / 2), ccp(0, 0)));
//章节的按钮
SGButton *chapButton = SGButton::createFromSprite(headIcon, headIcon1, this, menu_selector(SGSpecialBattleLayer::enterSpBattleSection));
chapButton->setTag(buttonTag);
//章节的名称 //250 197 68
SGCCLabelTTF *chapNameTTF = SGCCLabelTTF::create(data->chapName.c_str(), FONT_PANGWA, 24);
chapButton->addChild(chapNameTTF, 2);
chapNameTTF->setInsideColor(ccc3(250, 197, 68));
chapNameTTF->setPosition(ccpAdd(ccp(chapNameTTF->getContentSize().width / 2, chapNameTTF->getContentSize().height / 3.5), ccp(0, 0)));
//如果没有开启,蒙灰
if (!data->isOpen)
{
CCSprite *greyMask = CCSprite::createWithSpriteFrameName("sp_battle_entry_mask.png");
greyMask->setOpacity(150);
chapButton->addChild(greyMask, 10);
greyMask->setPosition(ccpAdd(ccp(greyMask->getContentSize().width / 2 - 5, greyMask->getContentSize().height / 2 - 5), ccp(0, 0)));
//未开启,不可用
chapButton->setEnabled(false);
}
CCMenu *menu = CCMenu::create();
menu->setTouchPriority(10);
menu->setPosition(CCPointZero);
menu->addChild(chapButton);
layerColor->addChild(menu);
chapButton->setPosition(ccpAdd(ccp(0, 0), ccp(layerColor->getContentSize().width / 2, layerColor->getContentSize().height / 1.5)));
//显示描述的背景
CCSprite *descBg = CCSprite::createWithSpriteFrameName("sp_battle_infobg.png");
layerColor->addChild(descBg, 1);
descBg->setPosition(ccpAdd(chapButton->getPosition(), ccp(0, -descBg->getContentSize().height / 2 - chapButton->getContentSize().height / 1.7)));
//下方对应的描述
std::string desc;
if (data->isOpen)
{
desc = data->chapOpenDesc;
//如果是开启的,加上光效
ResourceManager::sharedInstance()->bindTexture("animationFile/ms_niubility.plist", RES_TYPE_LAYER_UI, sg_specialBattleLayer);
CCSpriterX *newRewardEffect = CCSpriterX::create("animationFile/ms_niubility.scml", true, true);
layerColor->addChild(newRewardEffect, -1);
newRewardEffect->setanimaID(0);
newRewardEffect->setisloop(true);
newRewardEffect->setScale(1.15);
newRewardEffect->setPosition(ccpAdd(chapButton->getPosition(), ccp(0, 0)));
newRewardEffect->play();
}
else
{
desc = data->chapClosedDesc;
}
SGCCLabelTTF *chapDescTTF = SGCCLabelTTF::create(desc.c_str(), FONT_PANGWA, 21);
descBg->addChild(chapDescTTF, 1);
chapDescTTF->setPosition(ccpAdd(ccp(descBg->getContentSize().width / 2, descBg->getContentSize().height / 2), ccp(0, 0)));
//如果开启状态,显示剩余次数
if (data->isOpen)
{
SGCCLabelTTF *residueTimeTTF = SGCCLabelTTF::create(CCString::createWithFormat(str_SpecailBattleResidueCoint, data->freePlayTimes)->getCString(), FONT_PANGWA, 20);
residueTimeTTF->setInsideColor(ccGREEN);
layerColor->addChild(residueTimeTTF, 1);
residueTimeTTF->setPosition(ccpAdd(descBg->getPosition(), ccp(0, -residueTimeTTF->getContentSize().height * 1.2)));
}
}
else
{
//没有的,直接问号显示
SGButton *chapButton = SGButton::create("sp_battle_unlock.png", "equipPinzhi_5_0.png", this, NULL);
chapButton->setEnabled(false);
layerColor->addChild(chapButton);
chapButton->setPosition(ccpAdd(ccp(0, 0), ccp(layerColor->getContentSize().width / 2, layerColor->getContentSize().height / 1.5)));
//.........这里部分代码省略.........
示例2: initScrollView
void SGAnnouncementLayer::initScrollView()
{
//ResourceManager::sharedInstance()->bindTexture("sgannouncementlayer/sgannouncementlayer2.plist", RES_TYPE_LAYER_UI, sg_announcementLayer);
m_scrollview->getContainer()->removeAllChildrenWithCleanup(true);
int positionY = 0;// Y轴纵向偏移,
int border_shift = 20;//内容窗口偏移
int text_wid_expand = 40;//文本区宽度扩展
if (CCEGLView::sharedOpenGLView()->getFrameSize().width == ipadResource.size.width
||CCEGLView::sharedOpenGLView()->getFrameSize().width == ipadhdResource.size.width)
{
text_wid_expand = 28;
}
//记录上一个内容窗口的底线位置
float lastWindowBorderPos = 0.0f;
for(int i = 0; i < m_arrayAnn->count(); i++)
//for (int i = 0; i < 6; i++)
{
//=======================获取数据================================
SGAnnouncementDataModel *ann = (SGAnnouncementDataModel *)m_arrayAnn->objectAtIndex(i);
CCString *title = ann->getTitle();
CCString *content = ann->getContent();
int viewId = ann->getViewId();//跳转至哪个页面
//=======================获取数据================================
CCLayer *layer = (CCLayer*)m_scrollview->getContainer();//获取scrollview的容器
CCLayerColor* contentWindow = initContentWindow(content, viewId > 0);
contentWindow->setAnchorPoint(ccp(0.5, 0));
contentWindow->ignoreAnchorPointForPosition(false);
CCSize cwSize = contentWindow->getContentSize();
CCSprite * sprite = CCSprite::createWithSpriteFrameName("Tips.png");
sprite->setScaleX(cwSize.width / 584.0);
sprite->setScaleY(cwSize.height / 522.0);
sprite->setPosition(ccp(cwSize.width * 0.5, cwSize.height * 0.5));
contentWindow->addChild(sprite, 2);
//根据上一个内容窗口的位置计算下一个窗口的位置
contentWindow->setPosition(ccp(layer->getContentSize().width * 0.5,
lastWindowBorderPos + border_shift));
/* tips.png图片拉长的倍数 */
float pngScale = cwSize.height / 522 ;
// CCLOG("*******************>>>");
// CCLOG("i = %d" , i);
// CCLOG("title = %s" , title->getCString());
// CCLOG("content = %s" , content->getCString());
// CCLOG("pos: x=%f , y = %f" , contentWindow->getPositionX() , contentWindow->getPositionY());
// CCLOG("cwSize: width=%f, height=%f", cwSize.width, cwSize.height);
// CCLOG("lastWindowBorderPos = %f" , lastWindowBorderPos);
// CCLOG("<<<********************");
lastWindowBorderPos = contentWindow->getPositionY() + cwSize.height;
//公告title
CCLabelTTF *label = CCLabelTTF::create(title->getCString(), FONT_PANGWA, 35);
label->setColor(COLOR_RED);
label->setAnchorPoint(ccp(0.5 , 1));
label->setPosition(ccp(cwSize.width *0.5f, cwSize.height - pngScale * 20));
contentWindow->addChild(label, 100);
//公告内容
// CCSize maybeTextSize = stringInLabelRect(content->getCString());
// CCLabelTTF *label_content=CCLabelTTF::create(content->getCString(), FONT_PENGYOU, 24,CCSizeMake(maybeTextSize.width + text_wid_expand * 4,maybeTextSize.height + text_hei_expand),kCCTextAlignmentLeft);
CCLabelTTF *label_content=CCLabelTTF::create(content->getCString(), FONT_PENGYOU, 24,CCSizeMake(cwSize.width - 40 * widthFactor, cwSize.height - label->getContentSize().height),kCCTextAlignmentLeft);
label_content->setAnchorPoint(ccp(0.5, 1));//内容顶线对齐
label_content->setColor(ccBLACK);
label_content->setPosition(ccp(label->getPositionX(), label->getPositionY() - label->getContentSize().height));
label_content->setZOrder(102);
contentWindow->addChild(label_content);
//点击前往按钮
if (viewId > 0) {
SGButton *goButton = SGButton::create("box_btnbg.png", NULL, this, menu_selector(SGAnnouncementLayer::AnnounceButton),CCPointZero,false,true);
CCString *go = CCString::createWithFormat(str_Hit_goto);
SGCCLabelTTF *go_label = SGCCLabelTTF::create(go->getCString(), FONT_PANGWA, 30);
goButton->addChild(go_label);
goButton->setTag(viewId);//跳转到某个视图界面
go_label->setPosition(ccp(goButton->getContentSize().width / 2, goButton->getContentSize().height / 2));
//立即前往Button
CCMenu *menu = CCMenu::create(goButton, NULL);
menu->setTouchPriority(0);
menu->setPosition(CCPointZero);
goButton->setScale(0.7);
goButton->setZOrder(200);
//goButton->setPosition(ccp(label->getPositionX(), goButton->getContentSize().height / 1.5));
goButton->setAnchorPoint(ccp(0.5, 0));
goButton->setPosition(ccp(label->getPositionX(), pngScale * 18));
menu->setZOrder(200);
contentWindow->addChild(menu);
}
layer->addChild(contentWindow);
//每次加对应的contentWindow的大小,为之后计算scrollview的内容体偏移
//.........这里部分代码省略.........
示例3: onEnter
void CCTransitionCrossFade::onEnter()
{
CCTransitionScene::onEnter();
// create a transparent color layer
// in which we are going to add our rendertextures
ccColor4B color = {0,0,0,0};
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCLayerColor* layer = CCLayerColor::layerWithColor(color);
// create the first render texture for inScene
CCRenderTexture* inTexture = CCRenderTexture::renderTextureWithWidthAndHeight((int)size.width, (int)size.height);
inTexture->getSprite()->setAnchorPoint( ccp(0.5f,0.5f) );
inTexture->setPosition( ccp(size.width/2, size.height/2) );
inTexture->setAnchorPoint( ccp(0.5f,0.5f) );
// render inScene to its texturebuffer
inTexture->begin();
m_pInScene->visit();
inTexture->end();
// create the second render texture for outScene
CCRenderTexture* outTexture = CCRenderTexture::renderTextureWithWidthAndHeight((int)size.width, (int)size.height);
outTexture->getSprite()->setAnchorPoint( ccp(0.5f,0.5f) );
outTexture->setPosition( ccp(size.width/2, size.height/2) );
outTexture->setAnchorPoint( ccp(0.5f,0.5f) );
// render outScene to its texturebuffer
outTexture->begin();
m_pOutScene->visit();
outTexture->end();
// create blend functions
ccBlendFunc blend1 = {GL_ONE, GL_ONE}; // inScene will lay on background and will not be used with alpha
ccBlendFunc blend2 = {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA}; // we are going to blend outScene via alpha
// set blendfunctions
inTexture->getSprite()->setBlendFunc(blend1);
outTexture->getSprite()->setBlendFunc(blend2);
// add render textures to the layer
layer->addChild(inTexture);
layer->addChild(outTexture);
// initial opacity:
inTexture->getSprite()->setOpacity(255);
outTexture->getSprite()->setOpacity(255);
// create the blend action
CCAction* layerAction = CCSequence::actions
(
CCFadeTo::actionWithDuration(m_fDuration, 0),
CCCallFunc::actionWithTarget(this, callfunc_selector(CCTransitionScene::hideOutShowIn)),
CCCallFunc::actionWithTarget(this, callfunc_selector(CCTransitionScene::finish)),
NULL
);
// run the blend action
outTexture->getSprite()->runAction( layerAction );
// add the layer (which contains our two rendertextures) to the scene
addChild(layer, 2, kSceneFade);
}
示例4: init
bool ResultScene::init()
{
bool result = GradientLayer::init();
if (result) {
setTitle(MessageResultTitle);
CCSize windowSize = CCDirector::sharedDirector()->getWinSize();
GameEngine *engine = GameEngine::sharedEngine();
CCSprite *braveImage = CCSprite::createWithSpriteFrameName("brave.png");
braveImage->setRotation(90);
braveImage->setPosition(ccp(windowSize.width / 2, windowSize.height - kBraveImageMarginTop - braveImage->getContentSize().height / 2));
this->addChild(braveImage);
CCLabelTTF *messageLabel = CCLabelTTF::create(engine->getResultMessage(), DefaultFontName, FontSizeSmall);
messageLabel->setPosition(ccp(windowSize.width / 2 + kBraveMessageAdjustX, windowSize.height - kBraveMessageMarginTop));
messageLabel->setAnchorPoint(ccp(0.0, 0.0));
this->addChild(messageLabel);
float boxBottom = kCommandAreaHeight + kCommandAreaMarginTop + kCommandAreaMarginBottom;
CCDrawNode *boxNode = CCDrawNode::create();
CCPoint contentBox[] = {ccp(kBoxMarginHorizontal, windowSize.height - kBoxMarginTop),
ccp(windowSize.width - kBoxMarginHorizontal, windowSize.height - kBoxMarginTop),
ccp(windowSize.width - kBoxMarginHorizontal, boxBottom),
ccp(kBoxMarginHorizontal, boxBottom)};
boxNode->drawPolygon(contentBox, 4, kBoxFillColor, 1, kBoxBorderColor);
this->addChild(boxNode);
CCString *scoreText = CCString::createWithFormat("%s:%d", MessageScoreText, engine->getScore());
CCLabelTTF *scoreLabel = CCLabelTTF::create(scoreText->getCString(), DefaultFontName, FontSizeNormal);
scoreLabel->setPosition(ccp(windowSize.width / 2, windowSize.height - kScoreLabelMarginTop));
this->addChild(scoreLabel);
map<hiberlite::sqlid_t, int> *foundItems = engine->getFoundItems();
map<hiberlite::sqlid_t, int>::iterator foundItemsIterator = foundItems->begin();
vector<Item> *items = engine->getItems();
float itemImageAreaMarginLeft = windowSize.width / 2 - ((kNumberOfLineItems / 2 - 1) * (kItemImageSize + kItemImageMarginHorizontal)) - kItemImageMarginHorizontal / 2 - kItemImageSize / 2;
int sumFoundItems = 0;
int index = 0;
while (foundItemsIterator != foundItems->end()) {
hiberlite::sqlid_t itemID = (*foundItemsIterator).first;
Item item = items->at(itemID - 1);
int count = (*foundItemsIterator).second;
const char *imageFileName = item->image.c_str();
int posX = index % kNumberOfLineItems;
int posY = index / kNumberOfLineItems;
CCPoint imagePosition = ccp(itemImageAreaMarginLeft + (kItemImageSize + kItemImageMarginHorizontal) * posX,
windowSize.height - kItemImageAreaMarginTop - (kItemImageSize + kItemImageMarginVertical) * posY);
CCSprite *itemImage = CCSprite::createWithSpriteFrameName(imageFileName);
itemImage->setPosition(imagePosition);
this->addChild(itemImage);
sumFoundItems += count;
if (count > kItemCountMax) {
count = kItemCountMax;
}
CCString *countText = CCString::createWithFormat("%d", count);
CCLabelTTF *countLabel = CCLabelTTF::create(countText->getCString(), DefaultFontName, FontSizeSmall);
countLabel->setPosition(ccpAdd(imagePosition, ccp(0, -kItemImageSize / 2 - kItemImageCountLabelAdjustY)));
this->addChild(countLabel);
foundItemsIterator++;
index++;
}
CCString *itemCountText = CCString::createWithFormat("%s:%d", MessageNumberOfFoundItemsText, sumFoundItems);
CCLabelTTF *itemCountLabel = CCLabelTTF::create(itemCountText->getCString(), DefaultFontName, FontSizeNormal);
itemCountLabel->setPosition(ccp(windowSize.width / 2, windowSize.height - kItemCountLabelMarginTop));
this->addChild(itemCountLabel);
CCLayerColor *retryLayer = CCLayerColor::create((ccColor4B){0x00, 0x00, 0x00, 0x00}, kCommandButtonWidth, kCommandButtonHeight);
CCLabelTTF *retryLabel = CCLabelTTF::create(MessageRetryButtonTitle, DefaultFontName, FontSizeNormal);
retryLabel->setPosition(ccp(kCommandButtonWidth / 2, kCommandButtonHeight / 2));
retryLayer->addChild(retryLabel);
CCMenuItem *retryItem = CCMenuItemLabel::create(retryLayer,
GameEngine::sharedEngine(),
menu_selector(GameEngine::startNewGame));
CCLayerColor *backTitleLayer = CCLayerColor::create((ccColor4B){0x00, 0x00, 0x00, 0x00}, kCommandButtonWidth, kCommandButtonHeight);
CCLabelTTF *backTitleLabel = CCLabelTTF::create(MessageBackTitleButtonTitle, DefaultFontName, FontSizeNormal);
backTitleLabel->setPosition(ccp(kCommandButtonWidth / 2, kCommandButtonHeight / 2));
backTitleLayer->addChild(backTitleLabel);
CCMenuItem *backTitleItem = CCMenuItemLabel::create(backTitleLayer,
GameEngine::sharedEngine(),
menu_selector(GameEngine::showTitle));
CCMenu *menu = CCMenu::create(retryItem, backTitleItem, NULL);
menu->alignItemsHorizontallyWithPadding(kCommandButtonPadding);
menu->setPosition(ccp(windowSize.width / 2, kCommandAreaMarginBottom + kCommandAreaHeight / 2));
this->addChild(menu);
}
//.........这里部分代码省略.........