本文整理汇总了C++中CCMenuItemImage::setCallback方法的典型用法代码示例。如果您正苦于以下问题:C++ CCMenuItemImage::setCallback方法的具体用法?C++ CCMenuItemImage::setCallback怎么用?C++ CCMenuItemImage::setCallback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCMenuItemImage
的用法示例。
在下文中一共展示了CCMenuItemImage::setCallback方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
// on "init" you need to initialize your instance
bool CGameMenu::init()
{
bool bRet = false;
do
{
CC_BREAK_IF(! CCLayer::init());
CCSize size = CCDirector::sharedDirector()->getWinSize();
// 菜单列表
CCSpriteFrameCache *pCache = CCSpriteFrameCache::sharedSpriteFrameCache();
pCache->addSpriteFramesWithFile("Image/GameMenu.plist");
// 菜单背景
CCSprite* m_pBackground = CCSprite::createWithSpriteFrame(pCache->spriteFrameByName("Background.png"));
m_pBackground->setPosition(ccp(size.width/2, size.height/2));
this->addChild(m_pBackground, 0);
// 星星
CCSprite* pStar = CCSprite::create("Image/Star.png");
CC_BREAK_IF(! pStar);
pStar->setPosition(ccp(size.width/2, size.height/2));
this->addChild(pStar, 1);
CCActionInterval* actionFade = CCFadeOut::create(2.0f);
CCActionInterval* actionFadeBack = actionFade->reverse();
CCActionInterval* seq2 = (CCActionInterval*)CCSequence::create(actionFade, actionFadeBack, NULL);
CCRepeatForever* pRepeatForever = CCRepeatForever::create(seq2);
pStar->runAction(pRepeatForever);
// 标题
CCSprite* pTitle = CCSprite::create("Image/Title.png");
CC_BREAK_IF(! pTitle);
pTitle->setPosition(ccp(size.width/2, size.height - 70));
this->addChild(pTitle, 2);
// 开始游戏
CCMenuItemImage *pMenuStart = CCMenuItemImage::create();
//pMenuStart->initWithTarget(this, menu_selector(CGameMenu::menuStartCallback));
pMenuStart->setCallback( CC_CALLBACK_1(CGameMenu::menuStartCallback,this) );
pMenuStart->setNormalSpriteFrame(pCache->spriteFrameByName("StartNormal.png"));
pMenuStart->setSelectedSpriteFrame(pCache->spriteFrameByName("StartSelected.png"));
pMenuStart->setPosition(ccp(size.width/2, 110));
// 游戏配置
CCMenuItemImage *pMenuOption = CCMenuItemImage::create();
//pMenuOption->initWithTarget(this, menu_selector(CGameMenu::menuOptionCallback));
pMenuOption->setCallback( CC_CALLBACK_1(CGameMenu::menuOptionCallback,this) );
pMenuOption->setNormalSpriteFrame(pCache->spriteFrameByName("OptionNormal.png"));
pMenuOption->setSelectedSpriteFrame(pCache->spriteFrameByName("OptionSelected.png"));
pMenuOption->setPosition(ccp(size.width/2, 75));
// 游戏结束
CCMenuItemImage *pMenuExit = CCMenuItemImage::create();
//pMenuExit->initWithTarget(this, menu_selector(CGameMenu::menuExitCallback));
pMenuExit->setCallback( CC_CALLBACK_1(CGameMenu::menuExitCallback,this) );
pMenuExit->setNormalSpriteFrame(pCache->spriteFrameByName("ExitNormal.png"));
pMenuExit->setSelectedSpriteFrame(pCache->spriteFrameByName("ExitSelected.png"));
pMenuExit->setPosition(ccp(size.width/2, 40));
// 游戏菜单
CCMenu *pMenu = CCMenu::create(pMenuStart,pMenuOption, pMenuExit, NULL);
pMenu->setPosition(ccp(0, 0));
this->addChild(pMenu, 3);
// 陨石掉落特效
m_pMeteorolite = CCParticleSun::create();
m_pMeteorolite->setTexture(CCTextureCache::sharedTextureCache()->addImage("Image/Fire.png"));
this->addChild(m_pMeteorolite, 1);
move(0);
this->schedule(schedule_selector(CGameMenu::move), 5.0f);
// 飞机
CCSprite* pPlane = CCSprite::create("Image/PlaneIco.png");
CC_BREAK_IF(! pPlane);
pPlane->setPosition(ccp(size.width/2, size.height/2));
this->addChild(pPlane, 2);
bRet = true;
}
while(0);
return bRet;
}