Any tutorials on how to make a slider for cocos2d that controls sounds that you guys recommend? Some of tutorials look a bit shady.
Asked
Active
Viewed 2,426 times
1 Answers
10
You can use the slider provides by the CCControlExtension and use the callback method to change the volume of your sound as explained here.
Here a "pseudo" code to show you how to achieved this:
// 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];
}
I hope it'll help you.

Community
- 1
- 1

Yannick Loriot
- 7,107
- 2
- 33
- 56
-
Thank you so much, any suggestions for putting it in a certain location? I was thinking about using rect, but don't know if there is a more efficient way. – Jhon Doe Jun 29 '12 at 14:09
-
What do you mean by location? To position it you just have to use the slider.position attribute. – Yannick Loriot Jun 29 '12 at 14:35