title: get a smooth animation for a canvas game
body: <p>How to get a better animation, dinamically, even when browser is busy or idle, for different devices which have different hardware capacity.</p>
  
  <p>I have tried many ways and still cannot find the right way to make the game to display a better animation.</p>
  
  <p>This is what i tried:</p>
  
  <pre><code>var now;
  var then = Date.now();
  var delta;
  
  window.gamedraw = function(){
  
     now = Date.now();
     delta = now - then;
  
     if(delta &gt; 18){
          then = now - (delta % 18);
          game_update();
     }
  
  }
  
  window.gameloop = setInterval(window.gamedraw,1);
  </code></pre>
  
  <p>18 is the interval value to update the game, but when browser is busy this interval is not good, and it needs to lower. How to get a better animation dinamically, even when browser is idle or busy ?</p>
  
  <p>I suppose that the interval value is the problem, because if interval is lower then game animation is very fast, if this value is 18 then game animation is good but not when browser is busy, and I do not have idea how to change it dinamically.</p>