actionscript 3 - Fighter game as3, problems with KeyboardEvent.KEY_DOWN -
well problem i'm having troubles fighter in game. if utilize key_down event and/or enter_frame, when hold downwards kick or punch button fighter continuously causes harm enemy want him either to, illustration kick , homecoming still position or kick , able hold position cause harm 1 time. here's code:
stage.addeventlistener(keyboardevent.key_down, enterattack); stage.addeventlistener(keyboardevent.key_up, exitattack); stage.addeventlistener(event.enter_frame, attackyes); stage.addeventlistener(event.exit_frame, attackno); function enterattack(evt:keyboardevent):void { if (evt.keycode == 84) { attack = true; } } function exitattack(evt:keyboardevent):void { attack = false; } function attackyes(evt:event):void { if (attack) { hero.gotoandstop("punch1"); checkhitred(); checkifdead(); } } function attackno(evt:event):void { if (!attack) { hero.gotoandstop("still"); } }
i trying remove listener somewhere made fighter didn't attack.
is there way prevent holding downwards kick/punch button?
any help appreciated
you have devise cooldowns abilities, e.g. "kick" can happen 1 time per 20 frames. so, when player presses kick button, char kick, damage, , sets cooldown variable. come in frame listener starts decrement counter, , subsequent kick commands ignored while cooldown active.
stage.addeventlistener(keyboardevent.key_down, enterattack); stage.addeventlistener(event.enter_frame, enterframe); var kickcooldown:int=0; function enterattack(evt:keyboardevent):void { if (evt.keycode == 84) { if (!kickcooldown) { attack = true; kickcooldown=15; } } } function enterframe(evt:event):void { if (attack) { hero.gotoandstop("punch1"); attack=false; // have attacked once, dealing harm checkhitred(); checkifdead(); } if (kickcooldown>0) kickcooldown--; // waiting cooldown end else hero.gotoandstop("still"); // if ends, homecoming hero "still" posture }
actionscript-3 flash
No comments:
Post a Comment