iphone开发实现声音开关代码

  1. //Settings.h
  2. CCMenuItem *soundOnItem;
  3.     CCMenuItem*soundOffItem;
  4.     CCMenuItemToggle*soundToggleItem;
  5. //Settings.m
  6. -(void) soundButtonTapped: (id) sender
  7. {
  8.     if([CDAudioManagersharedManager].mute == TRUE){
  9.         [CDAudioManagersharedManager].mute = FALSE;
  10.     }
  11.     else{
  12.         [CDAudioManagersharedManager].mute = TRUE;
  13.     }
  14. }
  15. -(id)init{
  16.     if((self=[superinit])){
  17.         self.isTouchEnabled= YES;
  18.         soundOnItem= [CCMenuItemImage itemFromNormalImage:@"soundon1.gif"selectedImage:@"soundon1.gif" target:nil selector:nil];
  19.         soundOffItem= [CCMenuItemImage itemFromNormalImage:@"soundoff1.png"selectedImage:@"soundoff1.png" target:nil selector:nil];
  20.         soundToggleItem= [CCMenuItemToggle itemWithTarget:selfselector:@selector(soundButtonTapped:) items:soundOnItem,soundOffItem, nil];
  21.         CCMenu*bottomMenu = [CCMenu menuWithItems:soundToggleItem, nil];
  22.         bottomMenu.position= *****(25,95);
  23.         [selfaddChild: bottomMenu];
  24.     }
  25.     returnself;
  26. }

你可能感兴趣的:(iphone开发实现声音开关代码)