title: SetTimeOut() in THREE JS
body: <p>I realize a project for the master degree. 
  I must create a three js space invaders game.</p>
  
  <p>The project is well underway but i have a problem. My aliens ( THREE.Mesh object ) must be able to fire randomly. 
  To carry out that, i've created a function which should draw a random number. This function works. 
  The problem comes the animate() function. In fact i can't put a SetTimeOut() the animate() function. </p>
  
  <p>The SetTimeOut() works the first time animate() is called but after there is no timer. The code executing continually without waiting the timer.</p>
  
  <p>Maybe the problem coming because animate is continually called by requestAnimationFrame();</p>
  
  <p>My code : </p>
  
  <p>Index.html =></p>
  
  <pre><code>if (!init())animate();
  
  function animate(){
     requestAnimationFrame( animate );
     level1.animate();
  
     render();
  }
  </code></pre>
  
  <p>Level.js =></p>
  
  <pre><code>Level.prototype.animate = function()
  {
  
   //Timer doesn't work
   var that = this;
  
   //Just a test with a simple console.log test
   setTimeout(function() { console.log("test"); },10000);*/
  
  this.sky.rotation.x -=0.005;
  
  this.spaceship.fire();
  for (var i=0; i&lt;this.ducks.length;i++)
  {
     this.ducks[i].move();
      if (this.ducks[i].is_ready_to_fire())
          this.ducks[i].fire_if_ready();
  }
  </code></pre>
  
  <p>};</p>
  
  <p>With this example the program will wait 10 seconds the first time before print "test" and after the first call, print "test" without waiting.</p>
  
  <p>Have you any ideas ? </p>
  
  <p>Thank you very much. </p>
  
  <p>Sorry for my poor english. </p>