标签:class blog code http tar ext
设置按钮
点一下ON切换到OFF,点一下OFF切换到ON,实现:
创建菜单按钮
setimage = CCMenuItemImage::create("sound-on-A.png", "sound-off-A.png", this, menu_selector(Game::SetMusic)); setimage->setScale(0.5f); setimage->setPosition(ccp(size.width-20, size.height-20)); MUISC = false; CCMenu *menu2 = CCMenu::create(setimage, NULL); menu2->setPosition(CCPointZero); this->addChild(menu2);
void Game::SetMusic(CCObject* Object) { if (!MUISC)//禁音 ,off图标显示 { setimage->setNormalImage(CCSprite::create("sound-off-A.png"));//off可用 setimage->setDisabledImage(CCSprite::create("sound-on-A.png"));//on不可用 CocosDenshion::SimpleAudioEngine::sharedEngine()->stopBackgroundMusic(); MUISC = true; CCLOG("stop..."); } else //开启, on图标显示 { setimage->setNormalImage(CCSprite::create("sound-on-A.png"));//on可用 setimage->setDisabledImage(CCSprite::create("sound-off-A.png"));//off不可用 CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("MainMenu.mp3", true); MUISC = false; CCLOG("start..."); } }
Cocos2d-x又一种背景音乐设置方法,布布扣,bubuko.com
标签:class blog code http tar ext
原文地址:http://blog.csdn.net/oyangyufu/article/details/32712051