Michał Ratajczak
Michał Ratajczak

Reputation: 11

Sprite in Game Maker doesn't act the way I want it to

I'm currently working on animating my player so that he behaves like he's breathing.

if(time mod 60==0){
   if(image_index==0){
     image_index=1;
   }
   else{
     image_index=0;
   }
}
time++;

The whole thing is put in the step event and sprite is changing every single step and it even changes to an index 2 and 3, which I haven't even used in the code.

So if anyone has some ideas why does it work like this then please tell me.

Upvotes: 1

Views: 943

Answers (1)

An intern has no name
An intern has no name

Reputation: 496

It is because the sprite you use has multiple sub-images. GameMaker will naturally iterate the image index every frame. So first, you need to stop the animation from running with

image_speed = 0;

You have to run this line when the sprite has just been changed, so ideally just after the "sprite_index" variable is changed. If you don't change it, just set image_speed to zero in the creation code.

If you are curious, I found the answer here : How to freeze sprite animation on last frame?

Upvotes: 1

Related Questions