javascript - Tron game keyevent issue -


i want make 'tron-game like' little game, heres code, 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 press 1 of arrow keys , draw line, press different arrow key, there little break on drawing, line-drawing not continuous :/ advice?

i don't see break in demo provided.

anyway, first time push arrow, no line drawn.

i updated code, setting palette.context.beginpath() instruction before palette.context.moveto(), see jsfiddle result.

palette.context.beginpath(); palette.context.moveto(palette.x, palette.y); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -