注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

熊猫正正的博客

熊猫正正的天空

 
 
 

日志

 
 

cocos2d-音乐与音效(3)  

2013-06-02 18:07:59|  分类: ios游戏开发 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

-(id) init

{

// always call "super" init

// Apple recommends to re-assign "self" with the "super's" return value

if( (self=[super init]) ) {

        CGSize winSize = [CCDirector sharedDirector].winSize;

        

        NSString *fontName = @"myfont.fnt";

        

        CCLabelBMFont *playLabel = [CCLabelBMFont labelWithString:@"Touch to play music" fntFile:fontName];

        CCMenuItemLabel *playItem = [CCMenuItemLabel itemWithLabel:playLabel target:self selector:@selector(playSong:)];

        

        playItem.scale = 0.7;

        playItem.position = ccp(winSize.width/2,winSize.height*0.7);

        

        CCLabelBMFont *settingLabel = [CCLabelBMFont labelWithString:@"Setting" fntFile:fontName];

        CCMenuItemLabel *settingItem = [CCMenuItemLabel itemWithLabel:settingLabel target:self selector:@selector(settingSound:)];

        

        settingItem.position = ccp(winSize.width/2,winSize.height*0.35);

        

        CCMenu *menu = [CCMenu menuWithItems:playItem,settingItem, nil];

        menu.position = CGPointZero;

        [self addChild:menu];

}

return self;

}


- (void) playSong:(id) sender

{

    [[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"bgmusic.mp3" loop:YES];

}


- (void) settingSound: (id) sender

{

    [[SimpleAudioEngine sharedEngine] stopBackgroundMusic];

    CCTransitionSlideInL *transitionScene = [CCTransitionSlideInL transitionWithDuration:3.0 scene:[SoundSetting scene]];

    [[CCDirector sharedDirector] replaceScene:transitionScene];

}

---------------------------

#import <Foundation/Foundation.h>

#import "cocos2d.h"


@interface SoundSetting : CCLayer {

    

}


+(id) scene;


@end

-----------------------------------------


@implementation SoundSetting


+ (id) scene

{

    CCScene *scene = [CCScene node];

    SoundSetting *layer = [SoundSetting node];

    [scene addChild:layer];

    return scene;

}


- (id) init

{

    self = [super init];

    if (self)

    {

        CGSize winSize = [CCDirector sharedDirector].winSize;

        

        NSString *fontName = @"myfont.fnt";

        

        [CCMenuItemFont setFontName:@"Helvetica-Bold"];

        [CCMenuItemFont setFontSize:18];

        

        CCMenuItemFont *musicTitle = [CCMenuItemFont itemWithString:@"触摸下面的标签开启或关闭音乐"];

        [musicTitle setIsEnabled:NO];

        musicTitle.position = ccp(winSize.width*0.5,winSize.height*0.7);

        

        CCMenuItemFont *musicOn = [CCMenuItemFont itemWithString:@"On"];

        CCMenuItemFont *musicOff = [CCMenuItemFont itemWithString:@"Off"];

        CCMenuItemToggle *music = [CCMenuItemToggle itemWithTarget:self selector:@selector(changeStatus:) items:musicOff,musicOn, nil];

        music.position = ccp(winSize.width*0.5,winSize.height*0.6);

        

        CCLabelBMFont *returnLabel = [CCLabelBMFont labelWithString:@"Back to main menu" fntFile:fontName];

        CCMenuItemLabel *returnItem = [CCMenuItemLabel itemWithLabel:returnLabel target:self selector:@selector(backToMainMenu:)];

        returnItem.scale = 0.7;

        returnItem.position = ccp(winSize.width*0.5,winSize.height*0.35);

        

        CCMenu *menu = [CCMenu menuWithItems:musicTitle,music,returnItem, nil];

        menu.position = CGPointZero;

        [self addChild:menu];

        

        NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];

        if ([userDef boolForKey:@"music"] == NO)

            music.selectedIndex = 1;

    }

    

    return self;

}


- (void) changeStatus:(CCMenuItemToggle*) sender

{

    NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];

    

    if (sender.selectedIndex == 1)

        [userDef setBool:NO forKey:@"music"];

    if (sender.selectedIndex == 0)

        [userDef setBool:YES forKey:@"music"];

    

    if ([CDAudioManager sharedManager].mute == TRUE)

    {

        [CDAudioManager sharedManager].mute = FALSE;

    }

    else

    {

        [CDAudioManager sharedManager].mute = YES;

    }

}


- (void) backToMainMenu: (id) sender

{

    CCTransitionFlipX *transitionScene = [CCTransitionFlipX transitionWithDuration:1.0 scene:[HelloWorldLayer scene]];

    [[CCDirector sharedDirector] replaceScene:transitionScene];

}


@end


  评论这张
 
阅读(76)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017