title: Simple html5+javascript game flickering
body: <p>I just started learning javascript, and i already faced some problems. I have a very simple "game" where you move red box with arrow keys and there is black background. I saw some topics about the same question and some of the guys says that make a buffer and other half says that don't do buffer because your browser does it for you. But anyway, I just thought that there is something wrong in my code because it's flickering but it's just so simple that i think it should not.</p>
  
  <pre><code>var canvas = document.getElementById('canvas');
  var ctx = canvas.getContext('2d');
  
  canvas.width = 800;
  canvas.height = 600;
  
  var mySprite = {
      x: 200,
      y: 200,
      width: 50,
      height: 50,
      color: '#c00'
  };
  var yvel = 0;
  var xvel = 0 ;
  var moved = false;
  var mspeed = 15;
  
  var keysDown = {};
  window.addEventListener('keydown', function(e) {
      keysDown[e.keyCode] = true;
  });
  window.addEventListener('keyup', function(e) {
      delete keysDown[e.keyCode];
  });
  
  function update() {
      if (37 in keysDown) {
      moved = true;
      if(xvel &gt; -mspeed){
          xvel -= 0.5;
          }
      }
      if (38 in keysDown) {
      moved = true;
          if(yvel &gt; -mspeed){
          yvel -= 0.5
          }
      }
      if (39 in keysDown) {
      moved = true;
          if(xvel &lt; mspeed){
          xvel += 0.5
          }
      }
      if (40 in keysDown) {
      moved = true;
          if(yvel &lt; mspeed){
          yvel += 0.5
          }
      }
      mySprite.x += xvel;
      mySprite.y += yvel;
      if(moved == false){
          xvel = xvel * 0.95;
          yvel = yvel * 0.95;
          }
      moved = false;
  
  }
  
  function render() {
      ctx.fillStyle = '#000';
      ctx.fillRect(0, 0, canvas.width, canvas.height);
      ctx.fillStyle = mySprite.color;
      ctx.fillRect(mySprite.x, mySprite.y, mySprite.width, mySprite.height); 
  }
  
  function run() {
      update();   
      render();
  }
  
  setInterval(run, 1000/60);
  </code></pre>
  
  <p>You can try it here:<a href="http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_canvas_empty" rel="nofollow">w3school</a>
  Just copy my code and put it inside  tags and change the "MyCanvas" name to "canvas"</p>