KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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. Jet.prototype.checkDirection = function () { if (this.isUpKey) { this.drawY -= this.speed; if (this.speed < 5) { this.speed += 0.1; } } if (this.isDownKey) { this.drawY += this.speed; if (this.speed < 5) { this.speed += 0.1; } } if (!this.isUpKey) { if (!this.isDownKey) { if (this.speed >= 0) { this.drawY -= this.speed; this.speed -= 1; } } } if (!this.isDownKey) { if (!this.isUpKey) { if (this.speed >= 0) { this.drawY += this.speed; this.speed -= 1; } } }
Tags (comma-separated)
Save Edits
Cancel