0

我正在尝试为我的游戏制作一个选项菜单,其中有 2 个设置。一种设置禁用游戏中的所有音乐,另一种禁用所有音效。如果用户选择禁用所有音效而不是音乐,那么当他退出游戏并返回游戏时,它应该记住他的设置。我已经尝试过无数次来创建这种系统,但它根本不适合我。我不知道如何创建它。有人可以帮忙吗?我对动作脚本相当陌生。

所有声音都从库中访问

4

2 回答 2

0

使用 SoundChannel 创建和控制单独的声音。使用 SharedObject 来存储用户选择。

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/SoundChannel.html http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net /SharedObject.html

于 2013-11-12T02:29:39.520 回答
0

答案是使用静态功能的声音管理器类,它将有两个公共布尔属性,然后您可以使用选项菜单单独设置它们。然后,每次您想要播放声音时,该类都会检查这些布尔值(为此,使用它的函数来播放声音)。一个例子:

public class SoundManager {
    private var _musicOn:Boolean;
    private var _soundOn:Boolean;
    private var _currentMusicChannel:SoundChannel;
    private var _currentMusicSelected:Sound; // what to start when music is enabled
    public static function get musicOn():Boolean { return _musicOn; }
    public static function set musicOn(value:Boolean):void {
        if (value==_musicOn) return;
        _musicOn=value;
        if (_musicOn) _currentMusicChannel=_currentMusicSelected.play();
        else if (_currentMusicChannel) {
            _currentMusicChannel.stop();
            _currentMusicChannel=null;
        }
    }
    public static function get soundOn():Boolean { return _soundOn; }
    public static function set soundOn(value:Boolean):void { _soundOn=value; } 
    // a simple version, as this is an example
    public static function playSound(someSound:String):void {
        var aSound:Sound=getSoundFromString(someSound); // TODO
        // ^ you have to devise a method to convert strings to sounds
        if (isMusic(aSound)) {
            // TODO, you should have either one music or a set of em, so if you're
            // trying to play a music, this should return true, otherwise false
            _currentMusicSelected=aSound;
            if (_musicOn) _currentMusicChannel=aSound.play();
        } else {
            // a simpler version, the more advanced version should allow instant mute
            if (_soundOn) aSound.play();
        }
    }
    // some other functions are missing from here, as well as sound library and support stuff
}
于 2013-11-12T04:03:26.180 回答