GML Simple question (Sprite somtimes freezes)

Schtipadoo

Member
when i make animations i want some to stop looping, i do that by setting the speed to 0 when it reaches the last frame

i use it for basic stuff and it works fine most of the time, only on the jumping sprites something wierd happens
when the animation plays it will stop and transition to the falling sprite, but when you jump right after landing the animation will be already on the last frame

it is quite annoying since ive i just cant seem to make them play correctly by other means

is there a way to reset the animations to the first frame when they change or simply another way to stop them from looping that might fix this?
 

kupo15

Member
You have to set the image_index back to 0 when you change your sprite. I usually create a script that takes the sprite index you want to change it to and auto sets the image index back to 0
 

Schtipadoo

Member
You have to set the image_index back to 0 when you change your sprite. I usually create a script that takes the sprite index you want to change it to and auto sets the image index back to 0
i have this scipt that handles all player sprites, it just plays them and has all the settings on it so i can tell it to stop looping and such
i usually call for it to be executed everytime i want but i think ill leave it always on so i can just change the variable "Sprite"
but how can i detect the change on sprite?

GML:
var Sprite = argument[0];
var Loop = argument[1];


sprite_index = Sprite;
image_speed = Speed;

if Loop = false{
if image_index > image_number -1{
image_speed = 0;
 }
} else {
Speed = 0.25;
}
 

Roderick

Member
You're setting image_speed to whatever is stored in Speed at the beginning of the function, and then setting Speed after, and only if the else clause fires. That's going to mess things up; exactly how depends on how Speed is used elsewhere, but that's probably the source of your problem.
 

kupo15

Member
Yeah you should split them up if you want to have that always on. It might be a good idea to make Loop variable not local. Also, its possible that the new image_index bug in 2.3 could be causing a problem where it auto loops back around when it goes past image_number instead of doing so at the end of the frame

GML:
//// sprite_set(Sprite,Loop);

var Sprite = argument[0];
var Loop = argument[1];

sprite_index = Sprite;
image_index = 0;
image_speed = Speed;
looping = Loop;
GML:
/// scr_loop();


if looping == false {
if image_index >= image_number{
image_index = image_number-1;
image_speed = 0;
}
 
Last edited:
Top