actionscript 3 - How to get mt character to attack -
i'm trying create beat em game , right got character attacking. have 3 attack animation far , works about. want, if player presses attack button character attack , if player keeps pressing attack button continue attack sequence (note: no want if player holds down key, has key press).
the problem if keep mashing attack button attacks problem goes next attack animation attack button down , don't want that. how can make go next attack animation once current attack animation has finished instead of jumping next frame midway of it's current attack animation. want character finish attack , if player still keys in attack key go next attack frame otherwise stop. have done far
package { import flash.display.movieclip; import flash.events.event; import flash.events.keyboardevent; import flash.ui.keyboard; public class player extends movieclip { //attack variables var attacking:boolean = false; var punches:int = 0; var punching:boolean = false; public function player() { stage.addeventlistener(keyboardevent.key_down,keypressed); addeventlistener(event.enter_frame,update); } function keypressed(event:keyboardevent):void { //note: need these listeners here stage.removeeventlistener(keyboardevent.key_down, keypressed); stage.addeventlistener(keyboardevent.key_up, keyup); //if key down if (event.keycode == 65) { attacking = true; punching = true; punches++; } } function update(event:event) { //if player not attacking if (attacking == false) { punching = false; punches = 0; } else if (attacking == true) { if (punching == true) { gotoandstop('jab' + punches); } } } function keyup(event:keyboardevent) { stage.addeventlistener(keyboardevent.key_down, keypressed); } } }
also within last frame of every attack animation have put down
import flash.display.movieclip; import flash.events.event; stop(); movieclip(parent).attacking = false; movieclip(parent).punches = 0;
not sure if method best way around or should create extended class/arrays if how this
change
if (punching == true) { gotoandstop('jab' + punches); }
to
if (punching && !attacking) { gotoandstop('jab' + punches); }
so basically, make sure animation isn't playing before (re)plays animation.
edit: though calling gotoandstop while still on frame, replay animations of children movieclips.
Comments
Post a Comment