Forum Topic: player attacking??

(85 views • 4 replies)

This topic is 1 page long.

<< < > >>
None

CrustySheet

Reply To Post Reply & Quote

Posted at: 3/1/09 08:00 AM

CrustySheet LIGHT LEVEL 03

Sign-Up: 05/03/06

Posts: 532

hey guys im using this code

if(space ){
	    this.gotoAndStop(3);
	    this._x += speed
	    this._xscale = 100;

ok so this tells it to goto the attack frame which i have a movieclip on that frame and it plays the animation ONLY if i hold space down, what do i need to d to tell it to goto that frame play the whole animation and THEN go back to the original animation?


None

5h4d3ofBl4ck

Reply To Post Reply & Quote

Posted at: 3/1/09 08:42 AM

5h4d3ofBl4ck DARK LEVEL 07

Sign-Up: 03/13/07

Posts: 128

Are you using AS3 or AS2?

If it's as2 then there are alot of problems there...

Here's what I would write in
First you need an onClipEvent hander inside the player.mc
Then you would have to start the if statement on the next line

Sort of like:
OnClipEvent (enterFrame) {
If {Key.isDown(Key.SPACE)) {
blah blah blah
blah blah blah
}
}

There ya go.


None

CrustySheet

Reply To Post Reply & Quote

Posted at: 3/1/09 09:02 AM

CrustySheet LIGHT LEVEL 03

Sign-Up: 05/03/06

Posts: 532

At 3/1/09 08:42 AM, 5h4d3ofBl4ck wrote: Are you using AS3 or AS2?

If it's as2 then there are alot of problems there...

Here's what I would write in
First you need an onClipEvent hander inside the player.mc
Then you would have to start the if statement on the next line

Sort of like:
OnClipEvent (enterFrame) {
If {Key.isDown(Key.SPACE)) {
blah blah blah
blah blah blah
}
}

There ya go.

lol no! thanks but no thats not the question :)
yes it is as2 and heres the full code
the problem i have is.. when you press the attack key it playes the whole aimation ONLY if oyu hold the key down but if you keep tapping the key it only plays the first frame of the animation and looks stupid. what i need is a code that allows me to press the key once and it plays the whole animation THEN it goes back to the walking animation so you cant keep pressing attack over and ove. you can only attack once until the animation has finished playing

player.onEnterFrame = function(){
	
//set vars
  speed = 10;
  left= Key.isDown(Key.LEFT);
  right = Key.isDown(Key.RIGHT);
  attackKey = Key.isDown(65);
  jumpKey = Key.isDown(Key.SPACE);
	
//movement
  if(right){
	  if(attackKey && !jumpKey){
	    this.gotoAndStop(3);
	    this._x += speed
	    this._xscale = 100;
	  }else if(jumpKey){
	   this.gotoAndStop(5);
	   this._x += speed
	    this._xscale = 100;
	  }else{
		this.gotoAndStop(2);
	    this._x += speed
	    this._xscale = 100;
	  }
  }
  else if(left){
    if(attackKey && !jumpKey){
	    this.gotoAndStop(3);
	    this._x -= speed
	    this._xscale = -100;
	}else if(jumpKey){
	   this.gotoAndStop(5);
	   this._x -= speed
	    this._xscale = -100;
	  }else{
		this.gotoAndStop(2);
	    this._x -= speed
	    this._xscale = -100;
	  }
  }
  
 
  else{
	  if(attackKey){
		  this.gotoAndStop(4);
	  }else{
	this.gotoAndStop(1);
	  }
  }
}

None

Rudder21

Reply To Post Reply & Quote

Posted at: 3/1/09 09:54 AM

Rudder21 LIGHT LEVEL 03

Sign-Up: 11/27/08

Posts: 31

I use As3, and I don't have Flash CS3, which I'm gonna guess is what your using. But I do work with animations. I haven't had to do something like this yet, but i would find out the length of your animation and then connect it to an integer...

private var i:int; /*this is the number relating to the length of the animation */
public function Attack(e:Event): void {
if (Key.isDown(Space)) {
/* Do the animation */
removeEventListener(Event.ENTER_FRAME,At tack);
addEventListener(Event.EntEr_Frame, Animate);
}
publi function Animate(e:Event): void {
i++;
if (i == "HoweverLong the animation is") {
/*remove the animation*/
i = 0;
addeventListener(Event.ENTER_FRAme, Attack);
}

its a slightly ugly looking chunk of code, and like i said i have never used it before. But that would probably be my first approach to the problem. If it doesn't work then... MY BAD =P


None

Rudder21

Reply To Post Reply & Quote

Posted at: 3/1/09 09:56 AM

Rudder21 LIGHT LEVEL 03

Sign-Up: 11/27/08

Posts: 31

P.S. that was written in as3 style... Sorry


All times are Eastern Standard Time (GMT -5) | Current Time: 04:55 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!