本文整理汇总了C++中MenuItemToggle类的典型用法代码示例。如果您正苦于以下问题:C++ MenuItemToggle类的具体用法?C++ MenuItemToggle怎么用?C++ MenuItemToggle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MenuItemToggle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MenuItemToggle
MenuItemToggle * MenuItemToggle::create()
{
MenuItemToggle *ret = new MenuItemToggle();
ret->initWithItem(nullptr);
ret->autorelease();
return ret;
}
示例2: menuMusicToggleCallback
void TopMenu::menuMusicToggleCallback(Ref* pSender)
{
MenuItemToggle* menuMusic = (MenuItemToggle*)pSender;
CCLOG("selected index:%d",menuMusic->getSelectedIndex());
int select = menuMusic->getSelectedIndex();
switch (select) {
case 0:
{
Audio::getInstance()->setbIsOpenMusic(true);
Audio::getInstance()->playBGM();
}
break;
case 1:
{
Audio::getInstance()->setbIsOpenMusic(false);
Audio::getInstance()->pauseBGM();
}
break;
default:
break;
}
}
示例3: MenuItemToggle
MenuItemToggle* MenuItemToggle::create(MenuItem *item)
{
MenuItemToggle *pRet = new MenuItemToggle();
pRet->initWithItem(item);
pRet->autorelease();
return pRet;
}
示例4: new
MenuItemToggle* MenuItemToggle::create(MenuItem *item)
{
MenuItemToggle *ret = new (std::nothrow) MenuItemToggle();
ret->initWithItem(item);
ret->autorelease();
return ret;
}
示例5: ScrollingBgLayer
// on "init" you need to initialize your instance
bool OptionsMenu::init()
{
Size visibleSize = CCDirector::sharedDirector()->getVisibleSize();
Vec2 origin = CCDirector::sharedDirector()->getVisibleOrigin();
scrollingBgLayer = new ScrollingBgLayer(3.0);
this->addChild(scrollingBgLayer);
LabelBMFont *nameLabel = LabelBMFont::create("Options Menu","PixelFont.fnt");
nameLabel->setPosition(visibleSize.width/2, visibleSize.height * 0.8);
this->addChild(nameLabel);
MenuItemImage *presetItem = MenuItemImage::create("_bookgame_UI__resume.png",
"_bookgame_UI__resume.png",
CC_CALLBACK_1(OptionsMenu::reset, this));
presetItem->setPosition(ccp(visibleSize.width/2 - visibleSize.width * 0.125, visibleSize.height * 0.5));
MenuItemImage *pmainMenuItem = MenuItemImage::create("_bookgame_UI_mainmenu.png",
"_bookgame_UI_mainmenu.png",
CC_CALLBACK_1(OptionsMenu::mainMenu, this));
pmainMenuItem->setPosition(Vec2(visibleSize.width/2 + visibleSize.width * 0.125, visibleSize.height * 0.5 ));
//sound onoff items
soundOnItem = MenuItemImage::create("_bookgame_UI_soundON.png","_bookgame_UI_soundON.png", this,NULL);
soundOffItem = MenuItemImage::create("_bookgame_UI_soundOFF.png","_bookgame_UI_soundOFF.png", this,NULL);
bool isPaused = CCUserDefault::sharedUserDefault()->getBoolForKey("tinyBazooka_kSoundPausedKey");
MenuItemToggle* soundToggleItem;
if(isPaused == false) {
soundToggleItem = MenuItemToggle::createWithTarget(this,menu_selector(OptionsMenu::SoundOnOff),
soundOnItem, soundOffItem,NULL);
} else {
soundToggleItem = MenuItemToggle::createWithTarget(this,menu_selector(OptionsMenu::SoundOnOff),
soundOffItem, soundOnItem,NULL);
}
soundToggleItem->setPosition(ccp(visibleSize.width* 0.5, visibleSize.height * 0.5 ));
// create menu, it's an autorelease object
Menu* pMenu = Menu::create(pmainMenuItem, presetItem,soundToggleItem, NULL);
pMenu->setPosition(Vec2::ZERO);
this->addChild(pMenu, 10);
this->scheduleUpdate();
return true;
}
示例6: va_start
// XXX: deprecated
MenuItemToggle * MenuItemToggle::createWithTarget(Ref* target, SEL_MenuHandler selector, MenuItem* item, ...)
{
va_list args;
va_start(args, item);
MenuItemToggle *ret = new (std::nothrow) MenuItemToggle();
ret->initWithTarget(target, selector, item, args);
ret->autorelease();
va_end(args);
return ret;
}
示例7: va_start
// XXX: deprecated
MenuItemToggle * MenuItemToggle::createWithTarget(Object* target, SEL_MenuHandler selector, MenuItem* item, ...)
{
va_list args;
va_start(args, item);
MenuItemToggle *pRet = new MenuItemToggle();
pRet->initWithTarget(target, selector, item, args);
pRet->autorelease();
va_end(args);
return pRet;
}
示例8: plusMinusButtonCallback
void HelloWorld::plusMinusButtonCallback(Object* pSender)
{
MenuItemToggle *toggleItem = (CCMenuItemToggle *)pSender;
if (toggleItem->selectedItem() == _plusItem){
label->setString("Visible button: +");
}
else if (toggleItem->selectedItem() == _minusItem){
label->setString("Visible button: -");
}
}
示例9: init
bool TestJoystick::init()
{
if(!Layer::init())
{
return false;
}
m_isFollow = true;
Vec2 visibleOrigin = Director::getInstance()->getVisibleOrigin();
Size visibleSize = Director::getInstance()->getVisibleSize();
Sprite* pSprite = Sprite::create("HelloWorld.png");
pSprite->setPosition(Vec2(visibleOrigin.x + visibleSize.width / 2.0f,
visibleOrigin.y + visibleSize.height / 2.0f));
this->addChild(pSprite, 0);
MenuItemToggle* toggle = MenuItemToggle::createWithCallback(CC_CALLBACK_1(TestJoystick::menuItemToggleCallback,this),
MenuItemFont::create("follow"),
MenuItemFont::create("normal"),
NULL);
toggle->setAnchorPoint(Vec2(0.5f,0.5f));
this->addChild(Menu::create(toggle,NULL),1);
m_ball = CCSprite::create("ball.png");
m_ball->setScale(0.5f);
m_ball->setPosition(Vec2(200.0f,200.0f));
this->addChild(m_ball,2);
//创建摇杆实
m_joystick = Joystick::create("joystickBg.png",70.0f,"joystickHandle.png",50.0f);
m_joystick->setPosition(Vec2(70.0f,70.0f));
m_joystick->setVisible(false);
//摇杆触碰事件的回调
m_joystick->setHandleEventListener(JOYSTICK_CALLBACK(TestJoystick::moveSpr,this));
//触碰在摇杆外部的回调,用于follow模式下的摇杆,如果该回调返回true,则以后将继续接收JET_TOUCH_BEGIN,JET_TOUCH_MOVE和JET_TOUCH_END消息
m_joystick->setTouchOutsideCallback(CC_CALLBACK_2(TestJoystick::touchOutsideHandle,this));
this->addChild(m_joystick,3);
return true;
}
示例10: init
bool UILayoutTest_Layout_Relative_Location_Editor::init()
{
if (UIScene_Editor::init())
{
_layout = static_cast<Layout*>(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILayout/Relative_Align_Location/windows_ui_relative_align_location.json"));
_touchGroup->addChild(_layout);
this->configureGUIScene();
Menu* menu = static_cast<Menu*>(getChildByTag(1));
MenuItemToggle* menuItemToggle = static_cast<MenuItemToggle*>(menu->getChildByTag(1));
MenuItem* selectedItem = menuItemToggle->getSelectedItem();
menuItemToggle->setPosition(Vec2(VisibleRect::center().x, VisibleRect::center().y + selectedItem->getContentSize().height * 4.25f));
return true;
}
return false;
}
示例11: SwitchAudio
void Pause::SwitchAudio(Ref *Sender)
{
//this code makes sure that music is being enabled when needed and disabled properly
MusicD& md=MusicD::getHandle();
MenuItemToggle *toggleItem = (MenuItemToggle *)Sender;
if(toggleItem->getSelectedIndex()==0)
{
CocosDenshion::SimpleAudioEngine::getInstance()->resumeAllEffects();
md.SetIsAudioPlaying(true);
md.SetShouldAudioPlay(false);
}
else
{
CocosDenshion::SimpleAudioEngine::getInstance()->stopAllEffects();
md.SetIsAudioPlaying(false);
md.SetShouldAudioPlay(false);
}
}
示例12: switchLoadMethod
void UIListViewTest_Vertical_Editor::switchLoadMethod(cocos2d::Ref *pSender)
{
MenuItemToggle *item = (MenuItemToggle*)pSender;
if (item->getSelectedIndex() == 0){
_layout->removeFromParentAndCleanup(true);
_layout = static_cast<Layout*>(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/ui_listview_editor_1.json"));
_touchGroup->addChild(_layout);
this->configureGUIScene();
}else{
_layout->removeFromParentAndCleanup(true);
_layout = static_cast<Layout*>(cocostudio::GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UIListView_Editor/UIListView_Vertical_Editor/ui_listview_editor_1.csb"));
_touchGroup->addChild(_layout);
this->configureGUIScene();
}
}
示例13: new
// FIXME:: deprecated
MenuItemToggle * MenuItemToggle::createWithTarget(Ref* target, SEL_MenuHandler selector, const Vector<MenuItem*>& menuItems)
{
MenuItemToggle *ret = new (std::nothrow) MenuItemToggle();
ret->MenuItem::initWithCallback(std::bind(selector, target, std::placeholders::_1));
#if CC_ENABLE_GC_FOR_NATIVE_OBJECTS
auto sEngine = ScriptEngineManager::getInstance()->getScriptEngine();
if (sEngine)
{
for (const auto &item : menuItems)
{
if (item)
{
sEngine->retainScriptObject(ret, item);
}
}
}
#endif // CC_ENABLE_GC_FOR_NATIVE_OBJECTS
ret->_subItems = menuItems;
ret->_selectedIndex = UINT_MAX;
ret->setSelectedIndex(0);
return ret;
}
示例14: SwitchMusic
void Pause::SwitchMusic(Ref *Sender)
{
//this code makes sure that audio is being enabled when needed and disabled properly
MusicD& md=MusicD::getHandle();
MenuItemToggle *toggleItem = (MenuItemToggle *)Sender;
if(toggleItem->getSelectedIndex()==0)
{
if(!md.GetIsMusicPlaying())
{
CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("Music.mp3",true);
}
md.SetIsMusicPlaying(true);
md.SetShouldMusicPlay(false);
}
else
{
CocosDenshion::SimpleAudioEngine::getInstance()->stopBackgroundMusic();
md.SetIsMusicPlaying(false);
md.SetShouldMusicPlay(false);
}
}
示例15: CC_CALLBACK_2
//.........这里部分代码省略.........
auto quitLayer = QuitLayer::create();
quitLayer->setTag(1008);
quitLayer->setVisible(false);
this->addChild(quitLayer, 30);
auto listener = EventListenerKeyboard::create();
listener->onKeyReleased = [=](EventKeyboard::KeyCode code, Event * e){
switch (code)
{
case cocos2d::EventKeyboard::KeyCode::KEY_NONE:
break;
case cocos2d::EventKeyboard::KeyCode::KEY_BACK:
showQuit();
break;
default:
break;
}
};
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this);
signIn = SignIn::create();
signIn->setVisible(false);
this->addChild(signIn, 100);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
canStartGame = true;
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
if(GAMEDATA::getInstance()->isHasPaySignIn()){
if(CallAndroidMethod::getInstance()->isSignToday()){
canStartGame = true;
}else{
Audio::getInstance()->playSound("Music/sign_in.ogg");
signIn->setVisible(true);
canStartGame = true;
}
}else{
if(!GAMEDATA::getInstance()->getHasShowSignInPay() && !CallAndroidMethod::getInstance()->isHasShowSignInPay()){
CallAndroidMethod::getInstance()->pay(8);
GAMEDATA::getInstance()->setHasShowSignInPay(true);
}else{
canStartGame = true;
}
}
#endif
auto moreGameBtn = MenuItemImage::create(
"more_game_btn_normal.png", "more_game_btn_click.png", CC_CALLBACK_0(MenuLayer::showMoreGame, this)
);
moreGameMenu = Menu::create(moreGameBtn, NULL);
moreGameMenu->setPosition(740, 65);
moreGameMenu->setAnchorPoint(Point(0.5, 0.5));
moreGameMenu->setVisible(false);
this->addChild(moreGameMenu);
Audio::getInstance()->playBGM("Music/lobby_bg.ogg");
MenuItemImage* musicBtnOn = MenuItemImage::create("bg_music_open.png", "bg_music_open.png");
MenuItemImage* musicBtnOff = MenuItemImage::create("bg_music_close.png", "bg_music_close.png");
MenuItemToggle* musicTog = MenuItemToggle::createWithTarget(this, menu_selector(MenuLayer::getMusicState), musicBtnOn, musicBtnOff, NULL);
if (CocosDenshion::SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying())
{
musicTog->setSelectedIndex(0);
}
else
{
musicTog->setSelectedIndex(1);
}
auto musicMenu = Menu::create(musicTog, NULL);
musicMenu->setPosition(60, 65);
MenuItemImage* soundEffectOn = MenuItemImage::create("sound_effect_open.png", "sound_effect_open.png");
MenuItemImage* soundEffectOff = MenuItemImage::create("sound_effect_close.png", "sound_effect_close.png");
MenuItemToggle* soundEffectTog = MenuItemToggle::createWithTarget(this, menu_selector(MenuLayer::getSoudState), soundEffectOn, soundEffectOff, NULL);
if (GAMEDATA::getInstance()->getSoundState())
{
soundEffectTog->setSelectedIndex(0);
}
else
{
soundEffectTog->setSelectedIndex(1);
}
auto soundEffectMenu = Menu::create(soundEffectTog, NULL);
soundEffectMenu->setPosition(130, 65);
this->addChild(musicMenu);
this->addChild(soundEffectMenu);
signInPrize = SignInPrize::create();
this->addChild(signInPrize, 200);
signInPrize->setVisible(false);
//if (GAMEDATA::getInstance()->isFirstLogin() && Player::skillState <= 4){
//GAMEDATA::getInstance()->setFirstLogin(false);
//GameStateInfo::getInstance()->setGameState(Game_Pause);
//CallAndroidMethod::getInstance()->pay(1);
//}
this->scheduleUpdate();
return true;
}