Welcome Guest [Log In] [Register]
Welcome to Brackenwood. We hope you enjoy your visit.


You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Attack Button; How do I do this?
Topic Started: Mar 24 2006, 03:00 AM (195 Views)
boundless
Member Avatar
stuck in the third dimension
I was just wondering if there was a way to do this.

Basically all I need is for the 'a' key to begin the attack animation and make it so that any key that is pressed during the attack, wont do anything (including the 'a' itself).

As something extra (I dont know how it would be done) if you continue to hold 'a' through the attack animation, it wont continue to attack until you let go of the key and press it again.

Thank you guys so much for always lending a helping hand. I wouldn't even be as far as I am without you. Even with animation, brackenwood has really helped me develop my skills. Thanks again.
Offline Profile Quote Post Goto Top
 
Mr. Jiggmin
Member Avatar
made of tulips
Put something like this on the main timeline:
Code:
 
//keeps track of whether or not you're attacking
var attacking:Boolean = false;
//keeps track of whether or not the attack key is being held
var keyReleased:Boolean = true;
//runs every frame
onEnterFrame = function () {
//65 is the ascii code for "a". 66 is b, 67 is c, etc.
if (Key.isDown(65)) {
 //if you are not currently attacking and not holding down the attack button
 //from last time, you begin attacking
 if (attacking == false && keyReleased == true) {
  //you're attacking
  attacking = true;
  //you're holding down the attack button
  keyReleased = false;
  //starts the attack animation. replace attackAnim with whatever
  //instance name your character has.
  attackAnim.play();
 }
} else {
 //the attack button is not being held
 keyReleased = true;
}
};


Then put this on the first frame of the attack animation.
Code:
 
stop();
_root.attacking = false;


Hope that helps ya.
Offline Profile Quote Post Goto Top
 
boundless
Member Avatar
stuck in the third dimension
Hmm I'm having some trouble with this. Is it compatible with Flash MX (not 2004)?

I tried replacing attackAnim.play(); with _root.box_mc.gotoAndStop(6); because the character has the instance name box_mc and the attack animation is on the 6th frame of box_mc. That didn't work so I tried putting the code on box_mc rather than the main timeline only because all the code for the character is on box_mc.

I then put if (Key.isDown(Key.LEFT) && attacking == false && keyReleased == true) { on the other actions (walk left in that example). But all it did was stop those buttons from functioning. If it's for a different version of actionscript, then I'm sure all it needs is a little tweaking but I wouldn't know what to fix. Thanks for the help mr jiggmin :D
Offline Profile Quote Post Goto Top
 
Mr. Jiggmin
Member Avatar
made of tulips
Righto, you'll need to take the ":Boolean"s out of the code. That'll probably fix the other buttons as well...
Code:
 
//keeps track of whether or not you're attacking
var attacking = false;
//keeps track of whether or not the attack key is being held
var keyReleased = true;
//runs every frame
onEnterFrame = function () {
//65 is the ascii code for "a". 66 is b, 67 is c, etc.
if (Key.isDown(65)) {
//if you are not currently attacking and not holding down the attack button
//from last time, you begin attacking
if (attacking == false && keyReleased == true) {
 //you're attacking
 attacking = true;
 //you're holding down the attack button
 keyReleased = false;
 //starts the attack animation. replace attackAnim with whatever
 //instance name your character has.
 _root.box_mc.gotoAndStop(6);
}
} else {
//the attack button is not being held
keyReleased = true;
}
};


You'll need to move that code in the attack animation to the last frame, too.

:fpbls:
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Actionscript · Next Topic »
Add Reply