Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
27
rated 0 times [  33] [ 6]  / answers: 1 / hits: 32836  / 12 Years ago, mon, april 9, 2012, 12:00:00

In an HTML5 game I'm making, I play a thud sound when things collide. However, it is a bit unrealistic. No matter the velocity of the objects, they will always make the same, relatively loud thud sound. What I'd like to do is to have that sound's loudness depend on velocity, but how do I do that? I only know how to play a sound.



playSound = function(id)
{
sounds[id].play();
}


sounds is an array full of new Audio(url)'s.


More From » html

 Answers
11

Use the audio element's volume property. From 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.




Ex: sounds[id].volume=.5;


[#86357] Friday, April 6, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lailab

Total Points: 706
Total Questions: 102
Total Answers: 95

Location: Falkland Islands
Member since Mon, Jul 13, 2020
4 Years ago
;