Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try This, I used this Code and worked always.</p> <pre><code>@interface AppController : NSObject &lt;UIApplicationDelegate&gt; { bool isMusicOn; … } @property (nonatomic, assign) bool isMusicOn; @end @implementation AppController @synthesize isMusicOn; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { if([[NSUserDefaults standardUserDefaults] objectForKey:@"isMusicOn"] != nil) { self.isMusicOn = [[NSUserDefaults standardUserDefaults] boolForKey:@"isMusicOn"]; } else { self.isMusicOn = true; } if(self.isMusicOn) { [SimpleAudioEngine sharedEngine].backgroundMusicVolume = 1.0f; } else { [SimpleAudioEngine sharedEngine].backgroundMusicVolume = 0.0f; } } -(void) applicationWillResignActive:(UIApplication *)application { [[NSUserDefaults standardUserDefaults] setBool:self.isMusicOn forKey:@"isMusicOn"]; [[NSUserDefaults standardUserDefaults] synchronize]; } @end //Create Music button in your Cocos2d Scene @interface MySettingsScreen : CCLayer { CCMenuItemSprite *mMusicBtn; . . . } //in implementation file -(void)createButton { AppController *app = (AppController*)[UIApplication sharedApplication].delegate; NSString *imgName = ((!app.isMusicOn) ? @"mute.png" : @"musicOn.png" ); CCSprite *music_1 = [CCSprite spriteWithSpriteFrameName:imgName];//spriteWithFile if png is from file CCSprite *music_2 = [CCSprite spriteWithSpriteFrameName:imgName]; music_2.color = ccc3(200,200,200); mMusicBtn = [CCMenuItemSprite itemWithNormalSprite:music_1 selectedSprite:music_2 target:self selector:@selector(musicBtnPress:) ]; mMusicBtn.position = ccp(mS.width*0.25f, mS.height*0.1549f); } -(void)musicBtnPress:(id)sender { AppController *app = (AppController*)[UIApplication sharedApplication].delegate; if(app.isMusicOn) { [SimpleAudioEngine sharedEngine].backgroundMusicVolume = 0.0f; app.isMusicOn = false; mMusicBtn.normalImage = [CCSprite spriteWithSpriteFrameName:@"mute.png"]; //spriteWithFile if png is from file mMusicBtn.selectedImage = [CCSprite spriteWithSpriteFrameName:@"mute.png"]; //spriteWithFile if png is from file } else { app.isMusicOn = true; [SimpleAudioEngine sharedEngine].backgroundMusicVolume = 1.0f; mMusicBtn.normalImage = [CCSprite spriteWithSpriteFrameName:@"musicOn.png"]; mMusicBtn.selectedImage = [CCSprite spriteWithSpriteFrameName:@"musicOn.png"]; [[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"gr-theme.m4a" loop:YES]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload