本文整理汇总了C++中MenuItemSprite::setCallback方法的典型用法代码示例。如果您正苦于以下问题:C++ MenuItemSprite::setCallback方法的具体用法?C++ MenuItemSprite::setCallback怎么用?C++ MenuItemSprite::setCallback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MenuItemSprite
的用法示例。
在下文中一共展示了MenuItemSprite::setCallback方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createLayersContent
void ConfirmLayer::createLayersContent() {
GameModel* gameModel = GameModel::getInstance();
Face* backgroundFade = new Face();
backgroundFade->initWithFile(ANI_BACKGROUND_FADE);
backgroundFade->setPosition(Point(gameModel->getDisplayResolutionSize().width / 2, gameModel->getDisplayResolutionSize().height / 2));
backgroundFade->setOpacity(0);
this->mainLayer->addChild(backgroundFade);
this->backgroundFade = backgroundFade;
{
FiniteTimeAction* fadeIn = FadeIn::create(0.5f);
backgroundFade->registerState(STATE_FADE_IN, fadeIn);
FiniteTimeAction* fadeOut = FadeOut::create(0.5f);
backgroundFade->registerState(STATE_FADE_OUT, fadeOut);
}
Face* menuFace = new Face();
menuFace->initWithSpriteFrameName(ANI_BOX_CONFIRM);
menuFace->setPosition(Point(gameModel->getDisplayResolutionSize().width / 2, -500));
this->mainLayer->addChild(menuFace);
this->menuFace = menuFace;
Size menuFaceSize = menuFace->getContentSize();
UGMenu* optionMenu = UGMenu::create();
optionMenu->setPosition(Point::ZERO);
menuFace->addChild(optionMenu);
{
Label* confirmLabel = Label::createWithBMFont(FONT_GAME_SMALL, TXT_CONFIRM_TEXT);
confirmLabel->setPosition(menuFaceSize.width / 2, menuFaceSize.height / 2);
this->menuFace->addChild(confirmLabel);
}
{
FiniteTimeAction* move1 = MoveTo::create(0, menuFace->getPosition());
FiniteTimeAction* move2 = MoveTo::create(0.5f, Point(gameModel->getDisplayResolutionSize().width / 2, gameModel->getDisplayResolutionSize().height / 2));
FiniteTimeAction* move3 = CallFunc::create(CC_CALLBACK_0(ConfirmLayer::onOptionBoardMoveUpDone, this));
FiniteTimeAction* move123 = Sequence::create(move1, move2, move3, NULL);
menuFace->registerState(STATE_MOVE_UP, move123);
FiniteTimeAction* move4 = MoveTo::create(0, Point(gameModel->getDisplayResolutionSize().width / 2, gameModel->getDisplayResolutionSize().height / 2));
FiniteTimeAction* move5 = MoveTo::create(0.5f, menuFace->getPosition());
FiniteTimeAction* move6 = CallFunc::create(CC_CALLBACK_0(ConfirmLayer::onOptionBoardMoveDownDone, this));
FiniteTimeAction* move456 = Sequence::create(move4, move5, move6, NULL);
menuFace->registerState(STATE_MOVE_DOWN, move456);
MenuItemSprite* okButton = Utils::createButton((char*) TXT_OK, 16, ANI_BUTTON_SMALL, ANI_BUTTON_SMALL);
okButton->setCallback(CC_CALLBACK_1(ConfirmLayer::onOkButtonClick, this));
okButton->setPosition(Point(menuFaceSize.width / 2 - 129, 0));
okButton->setEnabled(false);
optionMenu->addChild(okButton);
this->okButton = okButton;
MenuItemSprite* cancelButton = Utils::createButton((char*) TXT_CANCEL, 16, ANI_BUTTON_SMALL, ANI_BUTTON_SMALL);
cancelButton->setCallback(CC_CALLBACK_1(ConfirmLayer::onCancelButtonClick, this));
cancelButton->setPosition(Point(menuFaceSize.width / 2 + 129, 0));
cancelButton->setEnabled(false);
optionMenu->addChild(cancelButton);
this->cancelButton = cancelButton;
}
}
示例2: init
bool WellcomeScene::init(){
log("wellcome scene init");
if(!Layer::init()){
return false;
}
Size vsize = Director::getInstance()->getVisibleSize();
Point origin = Director::getInstance()->getVisibleOrigin();
Sprite* bg = Sprite::createWithSpriteFrame(AtlasLoader::getInstance()->getSpriteFrameByName("bg_day"));
bg->setAnchorPoint(Point::ZERO);
bg->setPosition(Point::ZERO);
addChild(bg);
Sprite* title = Sprite::createWithSpriteFrame(AtlasLoader::getInstance()->getSpriteFrameByName("title"));
title->setPosition(Point(vsize.width/2, vsize.height - 10 - (((title->getSpriteFrame())->getRect()).size.height)));
addChild(title);
Sprite* land = Sprite::createWithSpriteFrame(AtlasLoader::getInstance()->getSpriteFrameByName("land"));
land->setAnchorPoint(Point::ZERO);
land->setPosition(Point::ZERO);
addChild(land);
Sprite *button = Sprite::createWithSpriteFrame(AtlasLoader::getInstance()->getSpriteFrameByName("button_play")),
*buttonTouch = Sprite::createWithSpriteFrame(AtlasLoader::getInstance()->getSpriteFrameByName("button_play"));
buttonTouch->setPositionY(-5);
MenuItemSprite *item = MenuItemSprite::create(button, buttonTouch);
item->setCallback(CC_CALLBACK_0(WellcomeScene::playButtonClickListener, this));
auto menu = Menu::create(item, NULL);
menu->setPosition(Point(vsize.width/2, vsize.height/2));
addChild(menu);
bird = BirdSprite::create();
bird->setPosition(Point(vsize.width/2, vsize.height/2 - 80));
addChild(bird);
bird->idle();
return true;
}
示例3: init
bool HomeLayer::init(){
bool isDay = UserDefault::getInstance()->getBoolForKey(DayTime, true);
string file = "modify/day_bg.png";
if (isDay == false) {
file = string("modify/night_bg.png");
}
if (GameLayerBase::initWithBgFileName(file.c_str())) {
Sprite* centerTitle = Sprite::create("modify/title.png");
centerTitle->setAnchorPoint(Vec2(0.5, 1.0));
centerTitle->setPosition(STVisibleRect::getCenterOfScene().x, STVisibleRect::getPointOfSceneLeftUp().y - 60);
addChild(centerTitle, 1);
//
// TableViewTest* pLayer = TableViewTest::create();
// this->addChild(pLayer, 2);
MenuItemSprite* lightBtn = CocosHelper::menuItemSprite("modify/night.png");
MenuItemSprite* settingBtn = CocosHelper::menuItemSprite("modify/setting.png");
MenuItemSprite* vedioBtn = CocosHelper::menuItemSprite("modify/video.png");
string soundFile = "modify/sound1.png";
if (!SoundPlayer::getInstance()->isMusicOpen()) {
soundFile = "modify/sound2.png";
}
MenuItemSprite* soundBtn = CocosHelper::menuItemSprite(soundFile.c_str());
MenuItemSprite* shareBtn = CocosHelper::menuItemSprite("modify/share.png");
lightBtn->setTag(kLightBtnTag);
settingBtn->setTag(kSettingBtnTag);
vedioBtn->setTag(kVedioBtnTag);
soundBtn->setTag(kSoundBtnTag);
shareBtn->setTag(kShareBtnTag);
lightBtn->setAnchorPoint(Vec2(0, 0));
settingBtn->setAnchorPoint(Vec2(1.0, 0));
vedioBtn->setAnchorPoint(Vec2(0.5, 0));
soundBtn->setAnchorPoint(Vec2(1.0, 0));
shareBtn->setAnchorPoint(Vec2(1.0, 0));
lightBtn->setPosition(Vec2(STVisibleRect::getOriginalPoint().x + 15, 60*0.618+STVisibleRect::getOriginalPoint().y));
settingBtn->setPosition(Vec2(STVisibleRect::getPointOfSceneRightBottom().x - 15, 60*0.618 + STVisibleRect::getOriginalPoint().y));
vedioBtn->setPosition(Vec2(STVisibleRect::getCenterOfScene().x, lightBtn->getBoundingBox().getMaxY() + 15));
soundBtn->setPosition(settingBtn->getPosition()+Vec2(15, 0));
shareBtn->setPosition(settingBtn->getPosition()+Vec2(15, 0));
lightBtn->setCallback(CC_CALLBACK_1(HomeLayer::onClickedMenuItems, this));
settingBtn->setCallback(CC_CALLBACK_1(HomeLayer::onClickedMenuItems, this));
vedioBtn->setCallback(CC_CALLBACK_1(HomeLayer::onClickedMenuItems, this));
Menu* pBtns = Menu::create(lightBtn, settingBtn, vedioBtn, NULL);
pBtns->setAnchorPoint(Vec2(0, 0));
pBtns->setPosition(Vec2(0, 0));
addChild(pBtns, 2);
float maxHeight = centerTitle->getBoundingBox().getMidY() - vedioBtn->getBoundingBox().getMaxY();
log("the max height is %.2f", maxHeight);
float tableHeight = maxHeight - 100*1.618;
float tableWidth = STVisibleRect::getGlvisibleSize().width - 200*0.618;
log("the tablewidth is %.2f, and the tableheight is %.2f", tableWidth, tableHeight);
int w = (int)tableWidth;
int h = (int)tableHeight;
TableViewTest* pLayer = TableViewTest::create(Size(w, h));
pLayer->setPosition(Vec2(100*0.618 + STVisibleRect::getOriginalPoint().x, vedioBtn->getBoundingBox().getMaxY() + 100*0.618));
addChild(pLayer, 10);
pLayer->setDelegate(this);
return true;
}
return false;
}
示例4: createLayersContent
void ChapterScene::createLayersContent() {
GameModel* gameModel = GameModel::getInstance();
Size displayResolutionSize = gameModel->getDisplayResolutionSize();
Face* backgroundFace = new Face();
backgroundFace->initWithFile(ANI_BACKGROUND);
backgroundFace->setScale(CONF_FAKE_1);
backgroundFace->setPosition(displayResolutionSize.width / 2, displayResolutionSize.height / 2);
this->backgroundLayer->addChild(backgroundFace);
Face* chapterTitle = new Face();
chapterTitle->initWithSpriteFrameName(ANI_CHAPTER_TITLE);
chapterTitle->setPosition(displayResolutionSize.width / 2, displayResolutionSize.height - chapterTitle->getContentSize().height / 2 - 20);
this->mainLayer->addChild(chapterTitle);
UGMenu* mainMenu = UGMenu::create();
mainMenu->setPosition(Point::ZERO);
this->mainLayer->addChild(mainMenu);
MenuItemSprite* backButton = Utils::createButton((char*) TXT_BACK, 16, ANI_BUTTON, ANI_BUTTON);
backButton->setCallback(CC_CALLBACK_1(ChapterScene::backButtonClick, this));
backButton->setPosition(gameModel->getDisplayResolutionSize().width / 2, 20 + backButton->getContentSize().height / 2);
mainMenu->addChild(backButton);
this->nodes->setObject(backButton, NODE_BUTTON_BACK);
// create chapters
this->chapterLayer = UGLayerColor::create();
float totalChapterSize = gameModel->getMapData()->getLevelSize();
float distancePerChapter = CONF_DISTANCE_PER_CHAPTER;
float totalChapterWidth = (totalChapterSize - 1) * distancePerChapter;
Face* chapterTemp = new Face();
chapterTemp->initWithSpriteFrameName(ANI_BOX_CHAPTER);
this->chapterTempSize = chapterTemp->getContentSize();
this->chapterLayer->setContentSize(Size(totalChapterWidth + this->chapterTempSize.width, displayResolutionSize.height / 2));
this->chapterLayer->setPosition(displayResolutionSize.width / 2 - this->chapterTempSize.width / 2, displayResolutionSize.height / 2 - this->chapterLayer->getContentSize().height / 2);
this->chapterLayerOffset = this->chapterLayer->getPosition();
this->mainLayer->addChild(this->chapterLayer);
float posX = this->chapterTempSize.width / 2;
float posY = this->chapterLayer->getContentSize().height / 2;
for (int i = 0; i < totalChapterSize; i++) {
Face* levelBox = new Face();
if (!gameModel->checkLevelLock(i + 1)) {
levelBox->initWithSpriteFrameName(ANI_BOX_CHAPTER);
levelBox->setTag(i + 1);
{
int chapter = gameModel->getMapData()->getChapter(i + 1);
int chapterLevel = gameModel->getMapData()->getChapterLevel(i + 1);
char mapPath[200];
sprintf(mapPath, DOC_BG_MAP, chapter, chapterLevel);
SpriteFrameCache* sfc = SpriteFrameCache::getInstance();
sfc->addSpriteFramesWithFile(mapPath);
char bg1Path[200];
sprintf(bg1Path, ANI_MAP, chapter, chapterLevel, 1);
Face* chapterThumb = new Face();
chapterThumb->initWithSpriteFrameName(bg1Path);
chapterThumb->setPosition(levelBox->getContentSize().width / 2, levelBox->getContentSize().height / 2 - 10);
chapterThumb->setTextureRect(Rect(0, 0, 160, 115));
levelBox->addChild(chapterThumb);
string levelName = gameModel->getMapData()->getLevelName(i + 1);
char levelNameChar[200];
sprintf(levelNameChar, "%s", levelName.data());
Label* levelNameLabel = Label::createWithBMFont(FONT_GAME_SMALL, levelNameChar);
levelNameLabel->setPosition(chapterThumb->getPosition() + Point(0, chapterThumb->getContentSize().height / 2 + 12));
levelBox->addChild(levelNameLabel);
}
} else {
levelBox->setTag(-1);
levelBox->initWithSpriteFrameName(ANI_BOX_CHAPTER_LOCK);
}
levelBox->setPosition(posX, posY);
posX = posX + distancePerChapter;
this->chapterLayer->addChild(levelBox);
}
// add parent button for share layer
this->shareLayer->getParentButtons()->pushBack((MenuItemSprite*) this->nodes->objectForKey(NODE_BUTTON_BACK));
}
示例5: createLayersContent
void LevelScene::createLayersContent() {
Size winSize = Director::getInstance()->getWinSize();
// create background
CSprite* backgroundFace = new CSprite();
backgroundFace->initWithFile(FRAME_BG);
backgroundFace->setPosition(winSize.width / 2, winSize.height / 2);
this->backgroundLayer->addChild(backgroundFace);
// create level title
CSprite* chapterTitle = new CSprite();
chapterTitle->initWithSpriteFrameName(FRAME_LEVEL_TITLE);
chapterTitle->setPosition(winSize.width / 2, winSize.height - chapterTitle->getContentSize().height / 2 - 20);
this->mainLayer->addChild(chapterTitle);
// create menu
Menu* mainMenu = Menu::create();
mainMenu->setPosition(Point::ZERO);
this->mainLayer->addChild(mainMenu);
// create back button
MenuItemSprite* backButton = CNodeUtil::createButton(FRAME_BACK_BUTTON, FRAME_BACK_BUTTON_SELECTED);
backButton->setCallback(CC_CALLBACK_1(LevelScene::backButtonClick, this));
backButton->setPosition(winSize.width / 2, 20 + backButton->getContentSize().height / 2);
mainMenu->addChild(backButton);
// create level layer
this->levelLayer = Layer::create();
int levelTotal = CONFIG_LEVELS_PER_CHAPTER;
int totalPageSize = ((levelTotal - 1) / CONF_TOTAL_LEVEL_SIZE_PER_PAGE) + 1;
int levelPerPage = CONF_TOTAL_LEVEL_SIZE_PER_PAGE;
int levelPerRow = levelPerPage / CONF_TOTAL_LEVEL_ROW;
int previousLevelTotal = this->getTotalPreviousLevel(this->currentChapter);
this->levelLayer->setContentSize(Size(winSize.width * totalPageSize, winSize.height / 1.5));
this->levelLayer->setPosition(0, winSize.height / 2 - this->levelLayer->getContentSize().height / 2);
this->levelLayerOffset = this->levelLayer->getPosition();
this->mainLayer->addChild(this->levelLayer);
for (int i = 0; i < levelTotal; i++) {
int level = i + 1;
CSprite* levelFace = new CSprite();
int realLevel = level + previousLevelTotal;
// if (gameModel->checkMapLock(realLevel)) {
levelFace->initWithSpriteFrameName(FRAME_BOX_LEVEL);
levelFace->setTag(realLevel);
{
char levelChar[10];
sprintf(levelChar, "%d", level);
Label* levelLabel = CNodeUtil::createLabelTTF(levelChar, 12);
levelLabel->setPosition(levelFace->getContentSize().width / 2, levelFace->getContentSize().height / 2);
levelFace->addChild(levelLabel);
}
// } else {
// levelFace->initWithSpriteFrameName(ANI_BOX_MAP_LOCK);
// levelFace->setTag(-1);
// }
this->levelLayer->addChild(levelFace);
int page = i / levelPerPage;
int row = ((level - (page * levelPerPage)) - 1) / levelPerRow;
int column = i % levelPerRow;
Point pagePosition = Point(winSize.width * page, 0);
float totalWidth = levelFace->getContentSize().width * levelPerRow + (10 * (levelPerRow + 1));
float totalHeight = levelFace->getContentSize().height * CONF_TOTAL_LEVEL_ROW + (10 * (CONF_TOTAL_LEVEL_ROW + 1));
float initX = (winSize.width - totalWidth) / 2;
float initY = this->levelLayer->getContentSize().height - ((this->levelLayer->getContentSize().height - totalHeight) / 2);
float levelPositionX = initX + (10 * (column + 1)) + (levelFace->getContentSize().width / 2 * (column + 1)) + (levelFace->getContentSize().width / 2 * column);
float levelPositionY = initY - (10 * (row + 1)) - (levelFace->getContentSize().height / 2 * (row + 1)) - (levelFace->getContentSize().height / 2 * row);
levelFace->setPosition(Point(levelPositionX, levelPositionY) + pagePosition);
}
}
示例6: 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;
}