• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Issues with image_index

I

Ike

Guest
Hey, so I'm trying to trigger a room_goto() event when my player's sprite is at frame 31, which is the last frame of the sprite animation. But it isn't working at all, it's just looping the sprite. I'm using a script to change character sprites so this is my code:

if place_meeting(x,y,obj_jetpack) {
sprite_index = spr_player_blast;
image_speed = 11;
if image_index >= 30 {
show_debug_message("HELLO???")
image_speed = 0;
room_goto(room1);
}
}

The show debug message doesn't even show the message, but my animation definitely gets to frame 30. The weird thing is when I was just trying to figure out the problem, I changed the number 30 to 3 and it worked! But the I changed it to 13 and it didn't work, so I don't know what's going on. I also have this code in the collision event for my obj_player and obj_jetpack because the animation won't even run unless it's in both. How can I fix this?
 
T

TinyGamesLab

Guest
The issue is that you have a image speed of 11, which means each step it advances 11 frames in your animation. Then, if the resulting value is bigger than 31, it loops around and restarts from 0.
Do you need it this high? If you set image_speed to 1 you will not have this issue (maybe remove some frames from the Sprite to get it quicker to the end sprite).
 

samspade

Member
Hey, so I'm trying to trigger a room_goto() event when my player's sprite is at frame 31, which is the last frame of the sprite animation. But it isn't working at all, it's just looping the sprite. I'm using a script to change character sprites so this is my code:

if place_meeting(x,y,obj_jetpack) {
sprite_index = spr_player_blast;
image_speed = 11;
if image_index >= 30 {
show_debug_message("HELLO???")
image_speed = 0;
room_goto(room1);
}
}

The show debug message doesn't even show the message, but my animation definitely gets to frame 30. The weird thing is when I was just trying to figure out the problem, I changed the number 30 to 3 and it worked! But the I changed it to 13 and it didn't work, so I don't know what's going on. I also have this code in the collision event for my obj_player and obj_jetpack because the animation won't even run unless it's in both. How can I fix this?
The problem is that your image speed is set to 11. 1 is equivalent to 100% of the speed you set in the sprite editor so an image speed of 11 means you want the image to move at 1100% of its default speed.

Game maker automatically loops the image index if it goes over. Depending upon the actual numbers, your might just never have got to image_index 31 at the right time. Because the image_index was progressing so quickly it is quiet likely it simply jumped past 30 and was looped to 0 before ever hitting that check.

To fix the problem, I would set image speed to something presumably a it more reasonable. I'd also use the animation end event. That's what its there for.
 
Top