仅关闭声音 - 如何?
我有一个问题:
如何仅在游戏中关闭声音?我问这个问题是因为我的设置中有两个按钮:打开/关闭音乐和打开/关闭声音。打开和关闭音乐非常容易,因为它使用特定的声道。但是如何仅关闭声音的音量(例如,音乐仍在播放,但游戏的声音已关闭)?
当我通过 SoundMixer.soundtransform 将声音静音时,您听不到任何声音,所以这不是我想要的。在我的游戏中,所有声音都被放入一个数组中。我的第一个想法是检查阵列中列出的所有声音并关闭音量,但这不起作用。拜托-有人可以帮忙吗?非常感谢。
//not working
private var sounds:Array;
private var soundChannels:Array = [];
private var muteSoundTransform:SoundTransform = new SoundTransform();
public function muteSoundOnly():void {
muteSoundTransform.volume = 0;
var soundLength:int = soundChannels.length - 1;
for (var soundCtr:int = soundLength; soundCtr >= 0; soundCtr--)
{
soundChannels[soundCtr].soundTransform = muteSoundTransform;
}
}
I have this problem:
How do you turn off the sound in a game only? I ask because I have two buttons in my settings: turn music on/off and sound on/off. turning music on and off is really easy because it uses a specific sound channel. But How do you turn off the volume the sound only (e.g. music is still playing but not the sound of the game)?
When I mute the sound via SoundMixer.soundtransform you can't hear anything so that's not what I wanted to have. In my game all sounds are thrown into an array. My first idea was that I go through all sounds listed in the array and turn off the volume but that's not working. Please - can anyone help? Thank you very much.
//not working
private var sounds:Array;
private var soundChannels:Array = [];
private var muteSoundTransform:SoundTransform = new SoundTransform();
public function muteSoundOnly():void {
muteSoundTransform.volume = 0;
var soundLength:int = soundChannels.length - 1;
for (var soundCtr:int = soundLength; soundCtr >= 0; soundCtr--)
{
soundChannels[soundCtr].soundTransform = muteSoundTransform;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这样做更容易:
然后在播放任何音效之前,确保声音已打开,如下所示:
如果您将静音按钮设为
soundsON = false;
,您的音效不会被播放。I think it's easier to do it like this:
and then before you play any sound effects, make sure sounds are ON, like so:
If you make your mute button do
soundsON = false;
, your sound effects won't be played.