We can make use of the
velocity capability we created in the
MySprite object.
Recall we created the object with this behaviour built-in:
MySprite.prototype.Do_Frame_Things = function() {
this.x = this.x + this.velocity_x; // move the thing
this.y = this.y + this.velocity_y;
if (this.visible) ctx.drawImage(this.MyImg, this.x, this.y); // draw the thing
}
So all we need to do is set the velocity !
The program below sets the velocity when a key goes down. Give it a try, but prepared to be surprised by the result.