cocos2d v3的音量滑块?

时间:2014-10-18 14:00:51

标签: ios iphone cocos2d-iphone

我想用音频滑块来控制cocos2d v3中的音量。 正如我在cocos2d v2中看到的那样,可以通过此https://github.com/YannickL/CCControlExtension创建滑块 但是在第3版它不起作用。我该怎么做?谢谢!

1 个答案:

答案 0 :(得分:0)

这里是我如何使用v3.2.1 CCSlider控件来做一个音频滑块。它是cocos标准UI玩具的一部分,使用它而不是扩展名:

CCSpriteFrame *frRuler = [CCSpriteFrame frameWithImageNamed:@"slider_track.png"];
CCSpriteFrame *frKnob  = [CCSpriteFrame frameWithImageNamed:@"slider_knob.png"];
_mainGain = [[CCSlider alloc] initWithBackground:frRuler andHandleImage:frKnob];
[self addChild:_mainGain];
[_mainGain setTarget:self selector:@selector(onMainGainChange:)];
_mainGain.positionType = CCPositionTypePoints;
_mainGain.anchorPoint  = ccp(.5, .5);
_mainGain.visible      = YES;
_mainGain.position     = ccp(kScreenWidth / 2, kScreenHeight / 2 - deviceOffset(55));
_mainGain.continuous   = YES;
_mainGain.sliderValue  = [BattlesStatus sharedBattlesStatus].settings.audio.masterVolumeGain;

每当更新间隔滑块滑动时,都会调用'onMainGainChanged:'选择器。我按如下方式处理:

- (void)onMainGainChange:(id)sender {

    CCSlider *sl = (CCSlider *) sender;
    TRACE(@"New setting is %f", sl.sliderValue);
    [BattlesStatus sharedBattlesStatus].settings.audio.masterVolumeGain = sl.sliderValue;
    _isSettingsDirty = YES;
}