javascript - 如何使游戏音量上升

标签 javascript html audio

声音功能

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/

相关文章:

javascript - 如何从php中的for循环中获取jquery值?

javascript - 计算父级边距的 outerHeight

php - 标签时在文本字段表中从上到下而不是从左到右聚焦

android - 更改 EditText 时播放声音 - android

javascript - 当我不知道 key 的名称时如何读取 json 对象

javascript - 在 Ember.js 中处理多态关系

php - 将 CSS 部分与 SMARTY + PHP 放在一起

javascript - 添加三个数字并使用 Javascript 在文本框中显示结果

audio - FFMPEG-音频文件的持续时间不准确

c++ - Allegro 5 一次播放多个样本