I need help to create a sound on and off button in my game.
Explanation:
- When sound off/on is tapped, I want it to show sound off/on
- I have a different scene and I want that button to get rid of sound on both scenes.
Please reply
A fast, easy to use, free, and community supported 2D game engine
I need help to create a sound on and off button in my game.
Explanation:
- When sound off/on is tapped, I want it to show sound off/on
- I have a different scene and I want that button to get rid of sound on both scenes.
Please reply
You could use NSUserDefaults to set a value and check it when each scene inits.
Here's what the button might look like:
// Mute Button
CCMenuItem *soundOn = [SoundMenuItem itemFromNormalSpriteFrameName:@"Controls_Sound_On_N.png" selectedSpriteFrameName:@"Controls_Sound_On_S.png" target:nil selector:nil];
CCMenuItem *soundOff = [SoundMenuItem itemFromNormalSpriteFrameName:@"Controls_Sound_Off_N.png" selectedSpriteFrameName:@"Controls_Sound_Off_S.png" target:nil selector:nil];
CCMenuItemToggle *soundToggle = nil;
if ([CDAudioManager sharedManager].mute) {
soundToggle = [CCMenuItemToggle itemWithTarget:self selector:@selector(muteSound) items:soundOff, soundOn, nil];
}else {
soundToggle = [CCMenuItemToggle itemWithTarget:self selector:@selector(muteSound) items:soundOn, soundOff, nil];
}
CCMenu *soundMenu = [CCMenu menuWithItems: soundToggle, nil];
[self addChild:soundMenu];
and the method:
-(void)muteSound
{
BOOL mute = [CDAudioManager sharedManager].mute;
[CDAudioManager sharedManager].mute = !mute;
}
That's a simplified version of what I do. I actually call the mute through a SettingsManager class and save it as a default, but you can do it however you'd like.
Thanks a lot for your help!
You must log in to post.