Home HTML Game : how play game over sound only once?
Reply: 0

HTML Game : how play game over sound only once?

totoaussi
1#
totoaussi Published in 2017-12-04 21:39:06Z

In my html game code source, I have the draw() function to draw in canvas. The draw() function is called repetitively by setinterval.

In the draw function, if gameOver variable is true, play gameover sound.

The problem is if the draw() function is called repetitively by setinterval (or requestAnimationFrame), the gameover sound is repeated at each draw() call. But I want play gameover only once.

Here the code :

function draw(){

if(isGameOver == true) { playGameOverSound(); }

}

setInterval(draw, 30);

What is the solution ?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.572598 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO