Here is my JS canvas code for a rectangular ship. If I comment out the switch statement, the ship is visible. On uncommenting the switch statement, the ship doesn't show. What's wrong?
var ship = function() {
this.velocityX = 0;
this.velocityY = 0;
this.accelerationX = 0;
this.accelerationY = 0;
this.x = width / 2;
this.y = height / 2;
this.speed = 4;
this.angle = 0;
this.control = function() {
context.save();
context.translate(this.x, this.y);
this.addEventListener("keydown", function(event) {
switch (event.keyCode) {
case 36:
this.accelerationX = Math.cos(this.angle) * this.speed;
this.accelerationY = Math.sin(this.angle) * this.speed;
break;
case 38:
this.accelerationX = -Math.cos(this.angle) * this.speed;
this.accelerationY = -Math.sin(this.angle) * this.speed;
break;
case 37:
this.angle -= 0.5;
break;
case 40:
this.angle += 0.5;
break;
}
});
context.rotate(this.angle);
context.fillStyle = "rgb(255,255,255)";
context.fillRect(0, 0, 20, 30);
context.restore();
};
};
this.