• 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!

How to let the code know which frame an animation is on

K

khaim0919

Guest
I am trying to make a tree grow and end up stopping. Previously I've done this with multiple different sprites but I think that an animation would look more organised.
 
you mean like

Code:
if (image_index = X){
image_speed = 0
}
X would be the frame of the sprite animation you want to stop on, just keep in mind that the frame count starts at 0. I think that might work?
 

Roldy

Member
The instance variable image_index stores the current frame.

The instance event Animation End will be called when an instance sprite passes the last frame. I recommend using the Event rather than manually tracking image_index.

 
Last edited:
K

khaim0919

Guest
if (image_index = 3) {
image_speed = 0;
}
if (mbleft = true) and (place_meeting(x,y,Object_Mouse)) and (image_speed = 0) {
instance_destroy();
}

This is what I currently have. its a 4 frame animation. It does not trigger whats inside the first if statement at all.
 

Roldy

Member
if (image_index = 3) {
image_speed = 0;
}
if (mbleft = true) and (place_meeting(x,y,Object_Mouse)) and (image_speed = 0) {
instance_destroy();
}

This is what I currently have. its a 4 frame animation. It does not trigger whats inside the first if statement at all.

Use Animation End event. You can just set image_speed to zero there.

Unless you are very thoughtful then you will find it difficult to re-implement Animation End on your own.


Image_index and Animation Event work with 'roll over.' On a 4 frame animation, the image_index will be 'valid' from 0-3. However, when image index is 4 or greater Animation End will trigger and shortly after image_index is reduced back under the valid range but retaining the remainder.
 
K

khaim0919

Guest
The instance variable image_index stores the current frame.

The instance event Animation End will be called when an instance sprite passes the last frame. I recommend using the Event rather than manually tracking image_index.

I just tried using this and it set the image speed to 0 when the first frame played on the second loop.
 
K

khaim0919

Guest
Thank you! Its working now. I had to set the image index back to 3 after setting the image speed though.
 

curato

Member
i like to get my image_index to image_number - 1 in the end animation even when I set the image_speed to zero. That way it is always the last frame no matter how many frames you have.
 
Top