PDA

View Full Version : [AS2] Attack movement and combos


Stink3301
08-13-2011, 09:46 AM
Hey, Im pretty new to flash. But using a tutorial, I made a decent fighting game. The only problem is that I want my character to move a little when he punches. I was wondering how could I make something move a limited space no matter how long you press the button.
I bet its simple, but I cant find anything.
And how could I make an attack combo? Like if I press the "A" button 3 times it plays 3 attacks but if i press it 2 times it only plays the first two attacks?

Thanks

Prid
08-14-2011, 02:25 PM
We can't help unless we some code ;)

But if you want him to move abit while he is attacking, increase the _x by a few when he attacks!

Also, for the Combo part, HERE IS A GREAT TUTORIAL (http://www.newgrounds.com/portal/view/455972) (click on CHAPTER, and then COMBOS)

Stink3301
08-15-2011, 10:31 PM
Yeah, i figured that one out. Instead of using "if (Key.isDown)" i used "on (key.Press)".

Just imagine I want to make a box move smoothly for, i dont know, 5 pixels. The way I did it makes it teleport 5 pixels, not the way i want.

Heres the code:
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
this._x -= 20
}
if (Key.isDown(Key.RIGHT)) {
this._x +=20
}
}

How could I make it move smoothly for, lets say, 5 seconds, no matter how long you hold the button?

Prid
08-15-2011, 11:06 PM
onClipEvent(load){
speed = 0;
maxSpeed = 20;
}

onClipEvent (enterFrame) {
this._x += speed;
if(Key.isDown(Key.LEFT)){
if(speed <= -maxSpeed){
speed = -maxSpeed;
} else {
speed--;
}
} else if(Key.isDown(Key.RIGHT)){
if(speed >= maxSpeed){
speed = maxSpeed;
} else {
speed++;
}
} else {
if(speed > 0){
speed--;
} else if(speed < 0){
speed++;
} else {
speed = 0;
}
}
}


what the code basically does, is that it declares two variables, one for the speed and the other for the maxSpeed, and then assign speed to the X coordinate of the movieclip. If RIGHT key is down, the speed should increase, and if it's above or equals to the maximum speed, then it should stay as the maxSpeed. And the same goes with LEFT key, just with that, we invert the maxSpeed, and DECREASE the speed. If none of the keys are down, then, if the speed is above 0, meaning that if you were moving RIGHT, then it should decrease, and the same with LEFT!

Stink3301
08-17-2011, 07:55 AM
thats great and thank you, but it doesnt answer my question.

When I press the attack button, my character does a punch and he makes a step while doing it. I want him to move fluidly with the step, not just teleport 5 pixels.
Get it?
Heres the code for the attack:
onClipEvent (enterFrame) {
if (Key.isDown(65)) {
this.gotoAndStop("attack1");
if (this.hitTest(_root.player2)) {
--_root.health2;
_root.player2.gotoAndStop("fall");
}
}
}


The other player has an animation for getting attack, which is named "fall".