• 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!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code Sprite animation doesn't work as expected.

kingyo

Member
IDE v2.3.4.580 / runtime v2.3.4.442

Sprite animations do not work as expected.
The code below expects the image_index to stop at 5, but it stops at 4.
What could be wrong with this code?
Is it a specification that this code does this? Is it a bug or something else?

Note
I know there are other simple ways to stop at frame 5. However, for some reason, I am using code like this. The explanation of the reason is omitted.

A sprite with frames from 0 to 5 is used.
cap01.PNG

GML:
Create event

image_speed = 0.2;
state = 0;
last_state = -1;


Step event

switch (state)
{
    case 0:
        if (image_index >= 5)
        {
            image_speed = 0;
            state = 1;
        }

        break;
   
    case 1:
        if (state != last_state)
        {
            image_index = 5;
            last_state = state;
        }
        break;
       
    default: break;
}
 
Last edited:
Top