【问题标题】:Sound slider for cocos2d?cocos2d 的声音滑块?
【发布时间】:2012-06-30 08:08:07
【问题描述】:

你们有什么推荐的关于如何为 cocos2d 制作一个控制声音的滑块的教程吗?有些教程看起来有点阴暗。

【问题讨论】:

    标签: iphone xcode4 cocos2d-iphone


    【解决方案1】:

    您可以使用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];
    }
    

    希望对你有帮助。

    【讨论】:

    • 非常感谢,有什么建议把它放在某个位置吗?我在考虑使用rect,但不知道是否有更有效的方法。
    • 位置是什么意思?要定位它,您只需使用 slider.position 属性。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-01
    相关资源
    最近更新 更多