title: Smooth character movement in canvas game using keyboard controls
body: <p>I'm creating a side-scrolling endless space themed game using canvas and JavaScript. I'm controlling a spaceship just by using the up and down arrows and I want to implement some kind of movement easing so that the ship doesn't just stop dead when I let go of the keys. I've looked around and haven't found anything plus my own attempts just aren't working. This is what I've tried.</p>
  
  <pre><code>Jet.prototype.checkDirection = function () {
  if (this.isUpKey) {
      this.drawY -= this.speed;
      if (this.speed &lt; 5) {
          this.speed += 0.1;
      }
  }
  if (this.isDownKey) {
      this.drawY += this.speed;
      if (this.speed &lt; 5) {
          this.speed += 0.1;
      }
  }
  if (!this.isUpKey) {
      if (!this.isDownKey) {
          if (this.speed &gt;= 0) {
              this.drawY -= this.speed;
              this.speed -= 1;
          }
      }
  }
  if (!this.isDownKey) {
      if (!this.isUpKey) {
          if (this.speed &gt;= 0) {
              this.drawY += this.speed;
              this.speed -= 1;
          }
      }
  }
  </code></pre>