Problems with Attack Animation

O

OwlTea

Guest
I feel like I should've solved this a long time ago but nothing seems to be working. Basically I have a two-frame attack animation that I want to play when the attack key is pressed and then the sprite goes back to it's one-frame idle pose.

What I've got is:

if(key_attack){
image_speed = .2; (not set in stone but just for testing purposes)
sprite_index = spr_partner_attack_1;
}
else{
sprite_index = spr_partner_idle_front;
}

But it seems like image_speed doesn't work properly with this code (and I checked, there's no other assignment of image_speed). The closest I can get it to behave is changing it to this:

if(key_attack){
image_speed = .2;
sprite_index = spr_partner_attack_1;
}
if(sprite_index = spr_partner_attack_1 && image_index >= 1.8){
sprite_index = spr_partner_idle_front;
}

But it still acts up and doesn't always play the full animation. I've been stuck on this stupid problem for days, can someone please tell me what I'm doing wrong so I can move on?
 
I'm going to assume that your code is in the Step Event. What you are doing is changing the sprite when the attack key is pressed, but the very next step the attack key is not pressed so the sprite is getting set back to the idle sprite.

Simplest thing I can think of for this is to have this in your Step Event:
Code:
if(key_attack){
image_speed = .2; (not set in stone but just for testing purposes)
sprite_index = spr_partner_attack_1;
}
and then put this in the Animation End to switch back to the idle animation once the animation of the attack sprite has completed.
Code:
if (sprite_index == spr_partner_attack_1) {
  sprite_index = spr_partner_idle_front;
}
 
O

OwlTea

Guest
I'm going to assume that your code is in the Step Event. What you are doing is changing the sprite when the attack key is pressed, but the very next step the attack key is not pressed so the sprite is getting set back to the idle sprite.

Simplest thing I can think of for this is to have this in your Step Event:
Code:
if(key_attack){
image_speed = .2; (not set in stone but just for testing purposes)
sprite_index = spr_partner_attack_1;
}
and then put this in the Animation End to switch back to the idle animation once the animation of the attack sprite has completed.
Code:
if (sprite_index == spr_partner_attack_1) {
  sprite_index = spr_partner_idle_front;
}
Alright, that almost works perfectly. It just seems to be stuttering, like sometimes it only plays the second frame? I'm not sure why it would be doing that.
 
Have you tried setting the image_index to 0 when you change to the spr_partner_attack_1 sprite (in the Step Event)? I can't remember if changing the sprite keeps it at the same frame that it was in the previous sprite/animation.
 
O

OwlTea

Guest
Omg it works perfectly now
I feel pretty stupid haha
Thank you so much!
 
Top