声音功能
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/