iphone - cocos2d 的声音 slider ?

标签 iphone xcode4 cocos2d-iphone

关于如何为 cocos2d 制作一个 slider 来控制声音,你们有推荐的教程吗?有些教程看起来有点可疑。

最佳答案

您可以使用 CCControlExtension 提供的 slider 并使用回调方法更改音量,如所述 here .

这里有一个“伪”代码向您展示如何实现此目的:

// Create your audio engine
[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"music.mp3"];

// Create the slider
CCControlSlider *slider = [CCControlSlider sliderWithBackgroundFile:@"sliderTrack.png" progressFile:@"sliderProgress.png" thumbFile:@"sliderThumb.png"];
slider.minimumValue = 0.0f; // Sets the min value of range
slider.maximumValue = 1.0f; // Sets the max value of range

// When the value of the slider will change, the given selector will be call
[slider addTarget:self action:@selector(valueChanged:) forControlEvents:CCControlEventValueChanged];

[self addChild:slider]; 

//...

- (void)valueChanged:(CCControlSlider *)sender
{
   // Change volume of your sounds
   [[SimpleAudioEngine sharedEngine] setEffectsVolume:sender.value];
   [[SimpleAudioEngine sharedEngine] setBackgroundMusicVolume:sender.value];
}

希望对你有帮助。

关于iphone - cocos2d 的声音 slider ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11250839/

相关文章:

cocos2d-iphone - 如何实现每帧运行的更新方法

ios - 如何打开/关闭音乐设置 objective-c

iphone - iOS应用程序后台下载

ios - 使 iPhone 6/6 plus 自动调整应用程序大小

ios - 在屏幕底部放置一个标签

ios - 在哪里管理 Xcode 4 中的构建配置?

ios - 用于签署可执行文件的身份不再有效

iphone - 使用 xcode 4 实现适用于 iPhone 的 Facebook Connect

iphone - sqlite3_prepare 错误 #26

ios - 在 Cocos2d 中加载 multipack spritesheet 时找不到文件