Skip to content
← Back to Community
Playing Sounds over other sounds.
Profile icon
Shigetorum

So, i am working in a fork of some kind osu!mania and i tought of making a hit sound in the game so when you pressed the key the sound played.
It works in general, the problem is that if you press the key more than twice, the sound just plays once. How can i fix this?

So far i have made this code:

<audio id="audio1" controls style="display:none"> <source src="https://osuskinner.com/elements/sounds/soft-hit-normal/1/70985.wav" type="audio/mpeg"> Your browser does not support the audio element. </audio> <audio id="audio2" controls style="display:none"> <source src="https://osuskinner.com/elements/sounds/soft-hit-normal/1/70985.wav" type="audio/mpeg"> Your browser does not support the audio element. </audio> <audio id="audio3" controls style="display:none"> <source src="https://osuskinner.com/elements/sounds/soft-hit-normal/1/70985.wav" type="audio/mpeg"> Your browser does not support the audio element. </audio> <audio id="audio4" controls style="display:none"> <source src="https://osuskinner.com/elements/sounds/soft-hit-normal/1/70985.wav" type="audio/mpeg"> Your browser does not support the audio element. </audio> <script> document.addEventListener('keydown', function(e) { if (e.keyCode == 68, 69, 74, 75) { document.getElementById('audio1').play(); } }); </script> <script> document.addEventListener('keydown', function(e) { if (e.keyCode == 69) { document.getElementById('audio2').play(); } }); </script> <script> document.addEventListener('keydown', function(e) { if (e.keyCode == 74) { document.getElementById('audio3').play(); } }); </script> <script> document.addEventListener('keydown', function(e) { if (e.keyCode == 75) { document.getElementById('audio4').play(); } }); </script>

Help is appreciated!

Edit: All keys press the sound too... why?

Answered by SixBeeps [earned 5 cycles]
View Answer
Voters
Profile icon
Thattimeago566
Profile icon
Vandesm14
Profile icon
Shigetorum
Comments
hotnewtop
Profile icon
SixBeeps

Have you thought about creating a new instance of the Hitsound and playing that instead of just calling a play method on one instance?

Also, I am a fellow circle clicker/key presser as well :)

Profile icon
Shigetorum

Thanks, helped me much!

You can check out the repl whenever you want to!