在我制作的 HTML5 游戏中,当物体发生碰撞时我会发出“砰”的一声。然而,这有点不现实。无论物体的速度如何,它们总是会发出相同的、相对响亮的“砰”的声音。我想做的是让声音的响度取决于速度,但我该怎么做呢?我只知道如何播放声音。
playSound = function(id)
{
sounds[id].play();
}
sounds
是一个充满 new Audio("url")
的数组。
最佳答案
使用音频元素的音量属性。来自 W3 :
The element's effective media volume is volume, interpreted relative to the range 0.0 to 1.0, with 0.0 being silent, and 1.0 being the loudest setting, values in between increasing in loudness. The range need not be linear. The loudest setting may be lower than the system's loudest possible setting; for example the user could have set a maximum volume.
例如:sounds[id].volume=.5;
关于javascript - 如何设置HTML5音频的响度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10075909/