I'm working on a game in JavaScript, and I want to change the way it behaves. What I am looking for is a way to change the direction of gravity every 10 seconds.
Here is my setInterval code, called in my draw() function, being ran whilst the game runs:
setInterval(function(){
changeGravity();
},10000);
and here is the code that is called:
function changeGravity(){
var rnd = Math.floor((Math.random() * 4) + 1);
var dir = direction[rnd];
gravity.direction = dir;
}
When ran, the interval lasts for 10 seconds before executing, however once executed it does not stop. What I'm looking for is for it to execute only once every 10 seconds.
Thanks for your help! :)
Aucun commentaire:
Enregistrer un commentaire