actionscript 3 - How to make movieClip dash by pressing the key double with AS3? -
so question clear think. if player press or d key movieclip moves normal. if player press or d , release , press or d character dash or sprint or whatever. here code :
function key_down(event:keyboardevent) { switch (event.keycode) { case 65 : leftkey = true; break; case 66 : punchkey = true; break; case 87 : upkey = true; break; case 68 : rightkey = true; break; case 83 : downkey = true; break; case 78 : jumpkey = true; break; case 77 : kickkey = true; break; } } function key_up(event:keyboardevent) { switch (event.keycode) { case 65 : leftkey = false; num++; if(num % 2 ==1){ canrun = true; } else { canrun = false; } break; case 66 : punchkey = false; punchbutton = true; break; case 87 : upkey = false; break; case 68 : rightkey = false; break; case 83 : downkey = false; break; case 78 : jumpkey = false; jumpbutton = true; break; case 77 : kickkey = false; kickbutton = true; break; } } if (leftkey || rightkey || downkey || upkey) { if (! isjumping && ! ispunching && ! iskicking && ! isrunning ) { // 5.frame walking animation speed = 7; hero.gotoandstop(5); } if(! isjumping && ! ispunching && ! iskicking && isrunning ){ // isrunning means character dashing // 17.frame sprint animation speed = 10; hero.gotoandstop(17); } if (leftkey) { hero.scalex = -1; speedx -= speed; } if (rightkey) { hero.scalex = 1; speedx += speed; }
this logic, you'll have tweak project though. works multiple keys btw.
var thresholdtime = 250; var delaysuntilkeyup = []; public function onkeydown(e):void { delaysuntilkeyup[e.keycode] = gettimer(); switch (event.keycode) { case 65 : //do break; } } public function onkeyup(e):void { delaysuntilkeyup[e.keycode] = gettimer() - delaysuntilkeyup[e.keycode]; switch (event.keycode) { case 65 : if( delaysuntilkeyup[e.keycode] <= thresholdtime ){ // when key released } else { // else, or maybe nothing } break; } }
Comments
Post a Comment