javascript - Problems with keydown events - control with setInterval -
if call without onkeydown function, works correctly. need run function -->only while spacebar pressed<--, , when left out finger of space bar, clearrect inside canvas.
that's function want control ->
function disparo(){ var forcax = 150; var movix = 846; document.onkeydown = function(event) { event = window.event; var e = event.keycode; if (e==32){ fill = setinterval(function(){ ctx.fillrect(forcax, 546, 1, 28); if(forcax < movix){ ctx.fillstyle = "#373dff"; forcax += 1; } if(forcax > movix) { forcax -= 1; } if(forcax == movix){ movix = 150; ctx.fillstyle = "#151515"; } if(forcax == 151){ movix = 846; } }, 8); } } }
Comments
Post a Comment