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

SOLVED Sprite Loop doesn't change

gkorn

Member
[Sorry if I'm posting this in wrong section]

So, first time here. I'm kinda new to Game Maker (not to game development), and am making a game for the Metroidvania Month.
Now I'm updating my rectangle mockups withh some free art mockup, so I can get a better feel of my FSM. But, I ran into a little problem:

When I uncheck the loop icon in the sprite editor, close the window and run the game, the animation is still looping.
I tried to uncheck it, close the window and re-open it to see, and it reversed as shown here:
I tried manually saving it with the window open, I even reinstalled GMS2 (changed it from my steam version to the downloaded-from-YoYo-site version).
It's not the 2.3 Beta, it's the stable version, up to date - I just reinstalled it.

I'm at the point that I'm thinking that I'll either drop the jam or restart it (losing 3 days of work, which is a lot for a metroidvania game in 1 month).
So if you guys could help me, I'd really appreciate.

(Sorry for any English mistakes, not native.)
 

Roldy

Member
Hi.

Those loop controls are only for preview window. The FPS controls actually effect the sprite at runtime. But the loop controls do not.

To get different play/loop effects at runtime you will have to adjust the instance variable: image_speed, image_index etc..
  • If you want it to not play the animation then set image_speed to zero.
  • If you want to not loop then set image_speed to zero in the Animation End event.
  • If you actually wanted to ping pong then you would have to implement that your self by setting image_speed to either 1 or -1 in Animation End.

i.e. The loop controls are just for previewing. To adjust playing or looping you have to do it via instance variables.

The manual states that the loop controls are preview only. Look at the section for Frame Controls:
 
Last edited:

IanTheOne

Member
Here:

GML:
if image_index >= (the maximum number of sub images in your sprite) { //checks if the animation ended
    image_speed = 0;//stops the animation from looping
}
You can also put it so if a certain condition is met the animation starts up again, you can also make it so it detects if the object currently has a certain sprite, hope this helps!
 

Roldy

Member
Here:

GML:
if image_index >= (the maximum number of sub images in your sprite) { //checks if the animation ended
    image_speed = 0;//stops the animation from looping
}
You can also put it so if a certain condition is met the animation starts up again, you can also make it so it detects if the object currently has a certain sprite, hope this helps!

Be careful of this.

It is easy for this condition to never be true depending on timing.

Internally and outside of direct control I believe the order of operation in Game Maker is thus:

After End Step but before the Animation End Event:
-- Increment image_index by the correct amount (depending on FPS or Frame per Step setting and image_speed)
Animation End will trigger if (mod image_index) >= image_number
Some point after Animation End and before Begin Step
-- if and only if ((image_index is > -image_number) || (image_index < 2 * image_number)) && (image_speed != 0) then
---- If image_index >= image_number then image_index = remainder of image_index / image_number
---- This works also for negative image_index

i.e. Game maker automatically restricts image_index to be in the range of (0, image_number) after the Animation End event iff image_index is within (-image_number, 2*image_number).
So as long as you never set image_index out of that range then Game maker will automatically modulate it for you when looping. However, if you set it out of range then it will stop doing so.

You can control this manually if you set image_speed to zero. But if image_speed is non zero then game maker may step on your toes when messing with image_index.

Just something to be aware of. And AFAIK it is undocumented behavior, which means be very careful on assuming it works any specific way depending on platform.
 
Last edited:

gkorn

Member
Wow, thank you SO MUCH for all your answers. I'll tag this post as solved since I got the answer I need, and I'll fiddle a bit around the code and other logic provided by you guys, and mayy even post the outcome here.

Again, thank you so much for your time and help. <3
 
Top