cocos2d的声音滑块?

时间:2012-06-28 18:33:34

标签: iphone xcode4 cocos2d-iphone

有关如何制作cocos2d滑块的任何教程,可以控制你们推荐的声音吗?一些教程看起来有点阴暗。

1 个答案:

答案 0 :(得分:10)

您可以使用CCControlExtension提供的滑块,并按照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];
}

我希望它会对你有所帮助。