2012-06-28 38 views

回答

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]; 
} 

我希望它會幫助你。

+0

非常感謝,有任何建議把它放在某個位置?我正在考慮使用矩形,但不知道是否有更有效的方法。 –

+0

你的位置是什麼意思?要定位它,你只需要使用slider.position屬性。 –

+0

感謝您的回答... – Guru