I want to make a 'Tron-game like' little game, heres the code, i already made: http://jsfiddle.net/Jim_Y/KQW5w/2/ code snippet:
$(document).keydown(function (e) {
if (e.keyCode == 37) {
// leftArrowPressed
palette.leftArrowPressed();
} else if (e.keyCode == 38) {
// topArrowPressed
palette.topArrowPressed();
} else if (e.keyCode == 39) {
// rightArrowPressed
palette.rightArrowPressed();
} else if (e.keyCode == 40) {
// bottomArrowPressed
palette.bottomArrowPressed();
}
return false;
});
Palette.prototype.leftArrowPressed = function () {
this.X = this.X - this.game.speed;
this.context.lineTo(this.X, this.Y);
this.context.stroke();
}
The problem is, when i press one of the arrow keys and draw a line, then press a different arrow key, there is a little break on the drawing, so the line-drawing is not continuous :/ Any advice?