Weird Issue With Sprite Images Playing Out of Order

N

Noth

Guest
So I wanted to give my character an animation for when he was crouching. The first three frames would play showing him getting down on the ground. Then he would freeze on the third frame where he would be ducking until the player released the control input for performing the ducking action. Then when the player releases, the last two frames would play showing the character getting back up. I finally got the sequence of freezing at the third frame and switching the state to standing on the last frame to work. The problem is... As my character performs the animation, he jumps to random frames before getting to the frame where he stops and ducks, and does the same thing as he gets back up. From observation, it seems that he starts at the first frame, jumps to the fourth frame, then the second, and finally the fifth before getting to the ducking frame where he's supposed to pause. And as I said, he does a similar thing when getting back up. I've spent several hours trying to wrap my head around what I could've done wrong. Any ideas? I'm kind of a newbie at coding so please bear with me.

Here is a sample of the code:

///scr_stand_check()
if ((!left_input and !right_input) and (grounded) or (left_input and right_input) and (grounded)) {
if (hspd == 0) and (state != "start") and (state != "ducking") and (state != "landing") {
state = "standing";
}
}
if (down_input) {
if (grounded) {
state = "ducking";
}
if ((state == "ducking") and (grounded) and (floor(image_index == 2)) and (sprite_index == spr_player_duck_l or sprite_index == spr_player_duck_r)) {
image_speed = 0;
}
} else {
if ((state == "ducking") and (grounded)) {
image_speed = 3;
if ((floor(image_index == 4)) and (sprite_index == spr_player_duck_l or sprite_index == spr_player_duck_r)) {
state = "standing";
}
}
}



///scr_state_check()
switch (state) {
case "standing":
switch (dir) {
case "left":
if (sprite_index != spr_player_stand_l) {
sprite_index = spr_player_stand_l;
image_index = 0;
image_speed = .3;
}
break;

case "right":
if (sprite_index != spr_player_stand_r) {
sprite_index = spr_player_stand_r;
image_index = 0;
image_speed = .3;
}
break;
}
break;

case "ducking":
switch (dir) {
case "left":
if (sprite_index != spr_player_duck_l) {
if (sprite_index != spr_player_duck_r) {
image_index = 0;
image_speed = 3;
}
sprite_index = spr_player_duck_l;
}
break;

case "right":
if (sprite_index != spr_player_duck_r) {
if (sprite_index != spr_player_duck_l) {
image_index = 0;
image_speed = 3;
}
sprite_index = spr_player_duck_r;
}
break;
}
break;
 
N

Noth

Guest
Never mind, guys. I found the problem. Turns out when you set image speed to something that exceeds the room speed, the animation will be glitchy. Can't believe I didn't think of it. xD
 

Soso

Member
Try setting the image_index = 0; when it starts state ducking
also it might help using an animation end event

what is your room speed btw?
 
Top