本文整理汇总了C++中MenuItemSprite::addChild方法的典型用法代码示例。如果您正苦于以下问题:C++ MenuItemSprite::addChild方法的具体用法?C++ MenuItemSprite::addChild怎么用?C++ MenuItemSprite::addChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MenuItemSprite
的用法示例。
在下文中一共展示了MenuItemSprite::addChild方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createMenuItem
MenuItemSprite* CardLevelUpLayer::createMenuItem(std::string spritename, std::string textname)
{
auto normal = Sprite::createWithSpriteFrameName(spritename + "0.png");
auto select = Sprite::createWithSpriteFrameName(spritename + "1.png");
auto disable = Sprite::createWithSpriteFrameName(spritename + "2.png");
auto text = Sprite::createWithSpriteFrameName(textname);
text->setPosition(normal->getContentSize().width / 2, normal->getContentSize().height / 2);
MenuItemSprite* menuItem = MenuItemSprite::create(normal, select, disable);
menuItem->addChild(text);
return menuItem;
}
示例2: addButton
bool DialogLayer::addButton(const char* title, Sprite* normalImage, Sprite* selectedImage, Sprite* disableImage, const ccMenuCallback& callback, int tag/* =0 */)
{
Size winSize = Director::getInstance()->getWinSize();
Point pCenter = Point(winSize.width / 2, winSize.height / 2);
// 创建图片菜单按钮
MenuItemSprite* menuImage = MenuItemSprite::create(normalImage, selectedImage, disableImage, callback);
menuImage->setTag(tag);
menuImage->setPosition(pCenter);
// 添加文字说明并设置位置
Size imenu = menuImage->getContentSize();
LabelTTF* ttf = CCLabelTTF::create(title, "Arial", 25);
ttf->setColor(Color3B(0, 0, 0));
ttf->setPosition(imenu.width / 2, imenu.height / 2);
menuImage->addChild(ttf);
getMenuButton()->addChild(menuImage);
return true;
}
示例3: init
bool MapLayer::init() {
if(!Layer::init()) {
return false;
}
cocos2d::Size s = Director::getInstance()->getWinSize();
DoodleTruck *doodleTruck = DoodleTruck::sharedDoodleTruck();
Sprite * bg_sprite = XSprite::xspriteWithFile(IMG_SPRITE_BG);
this->addChild(bg_sprite);
bg_sprite->setPosition(Vec2(s.width/2, s.height/2));
int cols = MAX_MAP / 2;
for (int i = 0; i < MAX_MAP; i++) {
char s1[100], s2[100];
sprintf(s1, "select level_%02d_nml.png", i + 1);
sprintf(s2, "select level_%02d_act.png", i + 1);
std::string level_nml = s1;
std::string level_act = s2;
Sprite *level_normal = XSprite::xspriteWithFile(level_nml);
Sprite *level_select = XSprite::xspriteWithFile(level_act);
//MenuItemSprite *item = [CCMenuItemImage itemFromNormalSprite:level_normal selectedSprite:level_select target:self selector:@selector(onMap:)];
//MenuItemSprite *[item = MenuItemImage::create(level_normal, level_select, <#const std::string &disabledImage#>, //);
MenuItemSprite* item = MenuItemSprite::create(level_normal, level_select, NULL, this, menu_selector(MapLayer::onMap));
map_menu[i] = item;
int col = i % cols + 1;
int row = i / cols;
item->setPosition(Vec2(s.width / (cols + 1) * col, s.height / 4.0f * (3 - row)));
int recorded_count = getRecordedCount(i);
int star_index = 0;
if (recorded_count >= getFineStoneNum(i))
star_index = 2;
else if (recorded_count >= getPassStoneNum(i))
star_index = 1;
if (star_index) {
Sprite *star_sprite = XSprite::xspriteWithFile("");//:[NSString stringWithFormat:@"star_%d.png", star_index]];
item->addChild(star_sprite);
star_sprite->setPosition(Vec2(star_sprite->getContentSize().width /2, star_sprite->getContentSize().height /2));
}
}
menu = Menu::createWithItem(map_menu[0]);
for (int i = 1; i < MAX_MAP; i++)
menu->addChild(map_menu[i]);
map_menu[doodleTruck->getMapIndex()]->selected();
Sprite *back_normal = XSprite::xspriteWithFile(IMG_BACK_NOR);
Sprite *back_select = XSprite::xspriteWithFile(IMG_BACK_HIGH);
MenuItemSprite* item_back = MenuItemSprite::create(back_normal, back_select, NULL, this, menu_selector(MapLayer::onBack));
Sprite *ok_normal = XSprite::xspriteWithFile(IMG_OK_NOR);
Sprite *ok_select = XSprite::xspriteWithFile(IMG_OK_HIGH);
MenuItemSprite* item_ok = MenuItemSprite::create(ok_normal, ok_select, NULL, this, menu_selector(MapLayer::onOk));
menu->addChild(item_back);
menu->addChild(item_ok);
item_back->setPosition(Vec2(s.width / 2.0f - s.width / 5.0f, item_back->getContentSize().height));
item_ok->setPosition(Vec2(s.width / 2.0f + s.width / 5.0f, item_ok->getContentSize().height));
menu->setPosition(Vec2(s.width, 0));
this->addChild(menu);
doneEnter();
return true;
}
示例4: init
bool ChoseLevel::init(PhysicsWorld* world){
if (!Layer::init()){
return false;
}
m_world = world;
visibleSize = Director::getInstance()->getVisibleSize();
origin = Director::getInstance()->getVisibleOrigin();
if (!database->getBoolForKey("isExit")){
database->setBoolForKey("isExit", true);
database->setIntegerForKey("nowLevel",0);
database->setIntegerForKey("nowStage",0);
level = 0;
stage = 0;
}
else{
level = database->getIntegerForKey("nowLevel");
stage = database->getIntegerForKey("nowStage");
}
Sprite* bgImage = Sprite::create("images/bg.png");
bgImage->setPosition(visibleSize.width/2, visibleSize.height/2);
this->addChild(bgImage,1);
auto homeItem = MenuItemImage::create("images/home.png","images/home.png",CC_CALLBACK_0(ChoseLevel::backHome,this));
auto homeMenu = Menu::createWithItem(homeItem);
this->addChild(homeMenu,5);
homeMenu->setPosition(visibleSize.width-homeItem->getContentSize().width/2, visibleSize.height-homeItem->getContentSize().height/2);
//auto levelOne = MenuItemLabel::create(Label::createWithTTF("Zero","fonts/arial.ttf",40),
// CC_CALLBACK_0(ChoseLevel::selectLevel,this,0));
//levelOne->setPosition(-2*levelOne->getContentSize().width,0);
//auto levelTwo = MenuItemLabel::create(Label::createWithTTF("One", "fonts/arial.ttf", 40),
// CC_CALLBACK_0(ChoseLevel::selectLevel, this, 1));
//levelTwo->setPosition(0,0);
//auto levelThree = MenuItemLabel::create(Label::createWithTTF("Two", "fonts/arial.ttf", 40),
// CC_CALLBACK_0(ChoseLevel::selectLevel, this, 2));
//levelThree->setPosition(2 * levelThree->getContentSize().width, 0);
//auto choseMenu = Menu::create(levelOne,levelTwo,levelThree,NULL);
//choseMenu->setPosition(visibleSize.width/2,visibleSize.height/2);
//this->addChild(choseMenu,2);
auto menuBg = Sprite::create("images/scroll.png");
menuBg->setPosition(visibleSize.width/2, visibleSize.height/2);
this->addChild(menuBg,2);
Vector<MenuItem*> levels;
MenuItemSprite* levelItem;
/*
for (int i = 0; i < unlock; i++){
auto normalSprite = Sprite::create("images/levelImage.png");
auto selectedSprite = Sprite::create("images/levelImage.png");
selectedSprite->setOpacity(200);
levelItem = MenuItemSprite::create(normalSprite, selectedSprite, CC_CALLBACK_0(ChoseLevel::selectLevel,this,i));
levelItem->setPosition(i*levelItem->getContentSize().width*3/2,0);
auto levelStr = String::createWithFormat("%d",i+1);
auto levelLabel = Label::createWithTTF(levelStr->getCString(),"fonts/arial.ttf",40);
levelLabel->setPosition(levelItem->getContentSize().width/2, levelItem->getContentSize().height/2);
levelItem->addChild(levelLabel);
levels.pushBack(levelItem);
}*/
int count = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++){
auto normalSprite = Sprite::create("images/levelImage.png");
auto selectedSprite = Sprite::create("images/levelImage.png");
selectedSprite->setOpacity(200);
levelItem = MenuItemSprite::create(normalSprite, selectedSprite);
levelItem->setPosition(i*levelItem->getContentSize().width*3/2, -j*levelItem->getContentSize().height*3/2);
if (count <= level){
levelItem->setCallback(CC_CALLBACK_0(ChoseLevel::selectLevel, this, count));
auto levelStr = String::createWithFormat("%d", count + 1);
auto levelLabel = Label::createWithTTF(levelStr->getCString(), "fonts/arial.ttf", 40);
levelLabel->setPosition(levelItem->getContentSize().width / 2, levelItem->getContentSize().height / 2);
levelItem->addChild(levelLabel);
count++;
}
else{
auto lock = Sprite::create("images/locked.png");
lock->setPosition(levelItem->getContentSize().width / 2, levelItem->getContentSize().height / 2);
levelItem->addChild(lock);
}
levels.pushBack(levelItem);
}
}
auto levelMenu = Menu::createWithArray(levels);
levelMenu->setPosition(visibleSize.width / 2 - levelItem->getContentSize().width * 3 / 2, visibleSize.height / 2 + levelItem->getContentSize().width/10*7);
this->addChild(levelMenu,3);
return true;
}