Be a Supporter!

Help needed to delay an animation.

  • 234 Views
  • 8 Replies
New Topic Respond to this Topic
snorte
snorte
  • Member since: Mar. 11, 2009
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Help needed to delay an animation. 2009-03-16 11:34:14 Reply

Hi. As the topic says, I have a character with three different animations within. One for jumping, one for punching and one for walking. The problem I have right now is that when i click "a" on my keyboard, which is the button that realeases the punching animation, the punch-animation will naturally start it's animation but as soon as I release the "a"-button it goes back to idle-stance. What I want to do is that when I push the button "a" I want the punchanimation to go to it's end and then go back to the idle-stance. And aswell as fullfilling the animation i want to make it impossible to do anything else while this animation is rolling. Thanks in advance for any help. :)

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to Help needed to delay an animation. 2009-03-16 11:43:18 Reply

At 3/16/09 11:34 AM, snorte wrote: The problem I have right now is that when i click "a" on my keyboard, which is the button that realeases the punching animation, the punch-animation will naturally start it's animation but as soon as I release the "a"-button it goes back to idle-stance.

You're going to have to post the code you're using

And aswell as fullfilling the animation i want to make it impossible to do anything else while this animation is rolling. Thanks in advance for any help. :)

You need a boolean (true/false variable) for that, eg 'punching'. Set it to true when the punch starts and reset it to false when the punch finishes. Then check that boolean on all other trigger/keypresses, and if it's true than don't run the other code.


- - Flash - Music - Images - -

BBS Signature
snorte
snorte
  • Member since: Mar. 11, 2009
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to Help needed to delay an animation. 2009-03-16 11:53:03 Reply

This is the attack-function I'm using.

function P1ATTACK() {
if(Key.isDown(65) && P1punch) {
mc.gotoAndStop("player1Punch");
P1punch = false;
}
if(!Key.isDown(65) && !P1punch) {
mc.gotoAndStop("player1Idle");
P1punch = true;
}
}

This is where I define the P1ATTACK()-function

function PLAYER1ACTION(mc) {
if(Key.isDown(Key.RIGHT) || Key.isDown(Key.LEFT)) {
P1MOVING(mc);
}
if(!Key.isDown(Key.RIGHT) && !Key.isDown(Key.LEFT) && !P1jumping &&!P1ATTACK) {
P1IDLE(mc);
}
P1JUMPING(mc);
P1ATTACK(mc);
if(mc._x > player2._x) {
mc._xscale = -100;
}
else {
mc._xscale = 100;
}

The function PLAYER1ACTION bounds all the player1-events.

snorte
snorte
  • Member since: Mar. 11, 2009
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to Help needed to delay an animation. 2009-03-16 11:55:48 Reply

Oh. I see now that the boolean P1punch was badly thought through. But since they do nothing, thats not the problem. :)

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to Help needed to delay an animation. 2009-03-16 12:00:56 Reply

At 3/16/09 11:53 AM, snorte wrote: function P1ATTACK() {
if(Key.isDown(65) && P1punch) {
mc.gotoAndStop("player1Punch");
P1punch = false;
}
if(!Key.isDown(65) && !P1punch) {
mc.gotoAndStop("player1Idle");
P1punch = true;
}
}

Not really sure why you'd need the second lump of P1ATTACK, it'd make more sense to just use

function P1ATTACK() {
	if(Key.isDown(65) && !P1punch) {
		mc.gotoAndStop("player1Punch");
		P1punch=true;
	}
}

and then add some actions to the last frame of the attack animation, something along the lines of

_root.P1Punch=false;
_root.mc.gotoAndStop("player1Idle");

- - Flash - Music - Images - -

BBS Signature
Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to Help needed to delay an animation. 2009-03-16 12:02:43 Reply

At 3/16/09 12:00 PM, Denvish wrote: _root.P1Punch=false;

*correction
_root.P1punch=false;


- - Flash - Music - Images - -

BBS Signature
snorte
snorte
  • Member since: Mar. 11, 2009
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to Help needed to delay an animation. 2009-03-16 12:11:28 Reply

Thanks alot. That worked out well.:) As always when a problem occur i tend to lock myself into one specific area that i think needs to be modified to make it work. xD I need to learn to broaden my mind i bit. Thanks alot again.:)

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to Help needed to delay an animation. 2009-03-16 12:45:15 Reply

At 3/16/09 12:11 PM, snorte wrote: Thanks alot. That worked out well.:) As always when a problem occur i tend to lock myself into one specific area that i think needs to be modified to make it work. xD I need to learn to broaden my mind i bit. Thanks alot again.:)

NP. The other alternative, if you want to keep actions all on the main timeline is to set up an onEnterFrame scan to see whether the attack animation's _currentframe is equal to its _totalframes (only while P1punch is true)


- - Flash - Music - Images - -

BBS Signature
snorte
snorte
  • Member since: Mar. 11, 2009
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to Help needed to delay an animation. 2009-03-16 13:47:02 Reply

Oh, okey :) Thanks again for your helpfulness. I had some problems getting everything to work out, but now it's all fixed and working as it's supposed to=)