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

GML Stop sprite on last frame in object

So i have this seriusly problem and i don't know how to make it working, i have this on my step event:


GML:
if (image_index >=6 && image_index<= 8)&&(sprite_index == spr_sonia_down_right){
            image_speed=0;
            image_index = 7;
}
The thing that i want is that on the last frame the sprite stop, i have an object and in that object i put the sprites or i change them using sprite_index and works, but my sprite down has a secuence that she is going down and down and down, when she is complete down that is in the 8 sub image i want to freeze the sprite on that frame but i can't reach that.
Im using game maker studio 2
 

curato

Member
use the animation end event then just check your sprite index set the image_speed to zero and then set image_index to image_number minus 1. Then when you are ready to change the sprite just make sure to set the image_speed back.
 
use the animation end event then just check your sprite index set the image_speed to zero and then set image_index to image_number minus 1. Then when you are ready to change the sprite just make sure to set the image_speed back.
Using this on animation end event:

GML:
if(sprite_index == spr_sonia_down_right){
image_speed = 0;
image_index = image_number -1;

}
Not working, what im doing wrong?
 
There's also this script

GML:
/// @description animation_end(sprite_index,image_index, rate)
/// @param {real} [sprite_index] The index of the sprite being animated
/// @param {real} [image_index] The current frame value
/// @param {real} [rate] -See Below-
///                                The rate of change in frames per step if not
///                                using built in image_index/image_speed. 
///                              If you don't think you need this.  You probably don't.
///  Returns true if the animation will loop this step.

var _sprite = argument_count > 0 ? argument[0] : sprite_index;
var _image = argument_count > 1 ? argument[1] : image_index;

var _type = sprite_get_speed_type(_sprite);
var _spd = sprite_get_speed(_sprite)*image_speed;
if(_type == spritespeed_framespersecond)
    _spd = _spd / room_speed;
if(argument_count > 2) _spd = argument[2];
return _image+_spd >= sprite_get_number(_sprite);
 

curato

Member
that should work. maker sure you aren't changing the animation speed anywhere else if you using that sprite.
 
There's also this script

GML:
/// @description animation_end(sprite_index,image_index, rate)
/// @param {real} [sprite_index] The index of the sprite being animated
/// @param {real} [image_index] The current frame value
/// @param {real} [rate] -See Below-
///                                The rate of change in frames per step if not
///                                using built in image_index/image_speed.
///                              If you don't think you need this.  You probably don't.
///  Returns true if the animation will loop this step.

var _sprite = argument_count > 0 ? argument[0] : sprite_index;
var _image = argument_count > 1 ? argument[1] : image_index;

var _type = sprite_get_speed_type(_sprite);
var _spd = sprite_get_speed(_sprite)*image_speed;
if(_type == spritespeed_framespersecond)
    _spd = _spd / room_speed;
if(argument_count > 2) _spd = argument[2];
return _image+_spd >= sprite_get_number(_sprite);
Well, so the thing that i did was in animation end event use a: script_execute, then i used a stoptest(spr_sonia_down_right,6, 1)); to call the script and run it, but idk, not working or maybe i did something wrong.
 
Last edited:
You would call my script in the step event.
if(animation_end()) image_speed = 0;

This is my sprite:
0.png
The object im using to switch between sprites is this and this is how i call the event that i named stoptest:
1.PNG
In the script im using this:
2.png
As result, im having this situation:
3.png
She is freezing yes, but not in the image_index that i want, is stopping on 1 sub-image (0, 1 , 2, 3 etc) as i saw, the sprites has 8 sub- images and she is freezing the animation on the 1st one :/
PD: i changed the call that was on animation end to step event as you said, but didnt work.

calling the script in step event and not on the animation end result in this:
4.png
but this is not the last frame.
 
Then something else is interfering. I've used that script a billion times and it fires not just on the last frame, but the last step that the last frame is displayed. If you need further help, I recommend discord. Getting help on the forums is a pain in the ass. There's a link to the GMS Discord server in my signature.
 
There's also this script

GML:
/// @description animation_end(sprite_index,image_index, rate)
/// @param {real} [sprite_index] The index of the sprite being animated
/// @param {real} [image_index] The current frame value
/// @param {real} [rate] -See Below-
///                                The rate of change in frames per step if not
///                                using built in image_index/image_speed.
///                              If you don't think you need this.  You probably don't.
///  Returns true if the animation will loop this step.

var _sprite = argument_count > 0 ? argument[0] : sprite_index;
var _image = argument_count > 1 ? argument[1] : image_index;

var _type = sprite_get_speed_type(_sprite);
var _spd = sprite_get_speed(_sprite)*image_speed;
if(_type == spritespeed_framespersecond)
    _spd = _spd / room_speed;
if(argument_count > 2) _spd = argument[2];
return _image+_spd >= sprite_get_number(_sprite);
Let me know if I'm wrong but I think this doesn't work when the speed in negative?
I've just added :

GML:
if(sign(_spd)) {
    return _image+_spd >= sprite_get_number(_sprite);
} else {
    return _image+_spd <= 0;
}
at the end of the script and everything work fine.
Thanks for the script :)
 
Top