gpt4 book ai didi

javascript - 如何使游戏音量上升

转载 作者:行者123 更新时间:2023-12-03 02:28:20 25 4
gpt4 key购买 nike

声音功能

function sound(src) {
this.sound = document.createElement("audio");
this.sound.src = src;
this.sound.setAttribute("preload", "auto");
this.sound.setAttribute("controls", "none");
this.sound.style.display = "none";
document.body.appendChild(this.sound);
this.play = function(){
this.sound.play();
}
this.stop = function(){
this.sound.pause();
}
}

把声音放进去
flying = new sound("flying.wav");

渲染声音-
flying.play()

我想知道的是,是否存在使WAV的音量增加的问题?

最佳答案

您只需与volume元素的 audio property交互。

这是我使用的文件中的示例函数,该文件为用户提供了一个向上和向下按钮,以通过.1在任一方向上调整音量,并确保它们不会将其设置为超出范围的值。这很不言自明。

function adjustVolume(increment) {
// Get the proposed new volume level and check that it
// is between 0 and 1 (inclusive) or you will throw an error.
var proposedV = audioElement.volume + increment;
if (proposedV >= 0 && proposedV <= 1) {
audioElement.volume = proposedV;
}
}

关于javascript - 如何使游戏音量上升,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52139262/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com