仅关闭声音 - 如何?

发布于 2024-12-11 21:08:41 字数 697 浏览 0 评论 0原文

我有一个问题:

如何仅在游戏中关闭声音?我问这个问题是因为我的设置中有两个按钮:打开/关闭音乐和打开/关闭声音。打开和关闭音乐非常容易,因为它使用特定的声道。但是如何仅关闭声音的音量(例如,音乐仍在播放,但游戏的声音已关闭)?

当我通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

江南月 2024-12-18 21:08:41

我认为这样做更容易:

var soundsON = true;

然后在播放任何音效之前,确保声音已打开,如下所示:

if (soundsON) {
 mySound.play();
}

如果您将静音按钮设为 soundsON = false;,您的音效不会被播放。

I think it's easier to do it like this:

var soundsON = true;

and then before you play any sound effects, make sure sounds are ON, like so:

if (soundsON) {
 mySound.play();
}

If you make your mute button do soundsON = false;, your sound effects won't be played.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文