1

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?

Community
  • 1
  • 1
Attila Kling
  • 1,717
  • 4
  • 18
  • 32

1 Answers1

0

I don't see any break in the demo you provided.

Anyway, the first time you push an arrow, no line is drawn.

I updated your code, by setting the palette.context.beginPath() instruction before palette.context.moveTo(), see jsfiddle for the result.

palette.context.beginPath();
palette.context.moveTo(palette.X, palette.Y);
Jérôme
  • 2,070
  • 15
  • 21