GML Code Equivalent for the "End Animation" Event?

A

Anomaly

Guest
Just as there's many parallels for events, like "meeting_place" = the collision event..

Is there code for end animation so I don't have to use another object and just use the sprite in my original object?
 
A

Anomaly

Guest
ok i've been using exactly that..

but hadn't set a new conditoinal in that "do something" in order to detour the remainder of code.
thanks for reminding me to look at that.
 

CMAllen

Member
WTF is this in GMS2? Why the hell would they force the Sprite animation speed in the Sprite itself? That's a horrible idea if that is what they did.
With GMS2, sprites now have a 'base' animation speed that you can set in the sprite itself (note: this effects all instance of that sprite in use). image_speed is now a multiplier of that base animation speed. If a sprite plays at 15fps, then setting image_speed to 2.0 will cause it to play at 30fps, and so forth.

There was something about the simplicity to the way GMS1.4 handle animation speeds that I liked, but there's value in the way GMS2 handles them too. I haven't decided which way I like more. -edit- Of course, the old image_speed system isn't really 'gone' either. It's nothing more than setting the image_speed value to 0, and incrementing image_index by whatever value is appropriate for the playback speed you want.
 

TheouAegis

Member
I would guess the reasoning was something along the lines of, "nobody ever uses deferring animation speeds between instances that use the same Sprite except in a situation such as adjusting the animation speed based on the movement speed of the instance, so we should just make it scale with image_speed."
 

poliver

Member
it is much handier.

don't think i've ever had to type image_speed in gms2, and if i'd need to there's still an option.
 

kupo15

Member
With GMS2, sprites now have a 'base' animation speed that you can set in the sprite itself (note: this effects all instance of that sprite in use). image_speed is now a multiplier of that base animation speed. If a sprite plays at 15fps, then setting image_speed to 2.0 will cause it to play at 30fps, and so forth.
Wow thanks for pointing this out. Another reason to not use image_speed built in but I can see it being handy in some cases.
 

TheouAegis

Member
Seems like it would have more overhead. Instead of just adding to the image_index, doesn't GM now have to check the speed type first?

But i see the usefulness after reading the help file on the change.
 
E

elsi11

Guest
This would trigger several times instead of once when the image speed is small, try and see for yourself.
Another reason to not use image_speed built in but I can see it being handy in some cases.
I'm using an animation as a trigger for something. Don't know if stuff can go wrong by using sprites for major events. But what I intend to do is: change the sprite index and the image index. Then, I'd wait for the animation end with
Code:
if (image_index == image_number)
At that point, I should be at the last frame, and ready for the major event. I thought about setting the image_speed to 0 so the animation stays at the last frame if it so happens that stuff doesn't get destroyed in time, but then I thought I'd rather not mess with image speed at all since I depend on the images rolling (saves me 1 line xD). Can I set the sprite_index to -1 or something so that I just erase the animation and it doesn't loop in case the object doesn't get destroyed in time? The easiest example is an explosion or death animation where you want to run the animation once and then that's it.

So my question, basically is whether something like this is good:
Code:
if (image_index == image_number)
{
    sprite_index = -1; //animation is over. Maybe we could put "image_index = image_number" as some kind of check mate infinite loop holding us at the last frame long enough for the other thing to run its course. I don't want to mess with speed.
    scr_super_major_event();
}
I'm on 1.4.
What do?
Also, is it customary to comment on ancient posts? This is the only forum I ever visited so I don't know the rules :)
 

Simon Gust

Member
I'm using an animation as a trigger for something. Don't know if stuff can go wrong by using sprites for major events. But what I intend to do is: change the sprite index and the image index. Then, I'd wait for the animation end with
Code:
if (image_index == image_number)
At that point, I should be at the last frame, and ready for the major event. I thought about setting the image_speed to 0 so the animation stays at the last frame if it so happens that stuff doesn't get destroyed in time, but then I thought I'd rather not mess with image speed at all since I depend on the images rolling (saves me 1 line xD). Can I set the sprite_index to -1 or something so that I just erase the animation and it doesn't loop in case the object doesn't get destroyed in time? The easiest example is an explosion or death animation where you want to run the animation once and then that's it.

So my question, basically is whether something like this is good:
Code:
if (image_index == image_number)
{
    sprite_index = -1; //animation is over. Maybe we could put "image_index = image_number" as some kind of check mate infinite loop holding us at the last frame long enough for the other thing to run its course. I don't want to mess with speed.
    scr_super_major_event();
}
I'm on 1.4.
What do?
Also, is it customary to comment on ancient posts? This is the only forum I ever visited so I don't know the rules :)
The examples above should work for you, don't be afraid to set image_speed in GMS 1.4.
Code:
if (image_index + image_speed >= image_number)
{
    image_speed = 0;
}
I do this too in my game and it works great.
 

kupo15

Member
It's fine to use animation end as a trigger for major events. I do it everywhere in my game. Just make sure to do what Simon said and make that check

>= image_number. If your image_speed isn't a clean number to land exactly on a whole it won't trigger (ie 4.15)

Code:
if >= image_number
{
image_speed = 0;
image_index = image_number-1; // need to set it to last frame to hold
}
 
N

NeZvers

Guest
I have upgraded Heartbeast solution for checking animation end.
Heartbeast checked if it's last image in sprite where I've adjusted so it doesn't cut short last image

Code:
///@description check if it's animation last step
var frame = image_index;
var frame_range = image_speed; //GMS2: var frame_range = image_speed * sprite_get_speed(sprite_index) / game_get_speed(gamespeed_fps);

return image_index >= image_number - frame_range && image_index < image_number;
 
J

Jenna

Guest
That does not work when you change the animation speed in the image editor. Then you have to use something like this:
Code:
(image_index+image_speed*sprite_get_speed(sprite_index) >= image_number)
Yay! This is exactly what I was looking for when I came here! I'd like to point out, though, that you need to have the sprite speed in your editor set to "frames per game frame" for this code to work correctly. By default it is set to "frames per second", so this was confusing me at first.
 

Flaick

Member
I have upgraded Heartbeast solution for checking animation end.
Heartbeast checked if it's last image in sprite where I've adjusted so it doesn't cut short last image

Code:
///@description check if it's animation last step
var frame = image_index;
var frame_range = image_speed; //GMS2: var frame_range = image_speed * sprite_get_speed(sprite_index) / game_get_speed(gamespeed_fps);

return image_index >= image_number - frame_range && image_index < image_number;
Thanks! You saved my life!
 
D

DannySantos

Guest
Bit late to the party but:

GML:
var last_frame_of_animation = image_number - sprite_get_speed(sprite_index)/room_speed;
image_index >= last_frame_of_animation;
This ensures that you are on the last frame of the last sub-image of the sprite animation.

image_index is the current sub-image of the sprite.
image_number is the total number of sub-images.
sprite_get_speed(sprite_index) returns the speed of the sprite as set in the GUI.
room_speed is the frame rate.

sprite_get_speed(sprite_index)/room_speed therefore returns the time increments that the image_index changes at. When you minus that from the image number you get the last frame of the last sub-image of the sprite animation. It is only when image_index is greater than or equal to that number that you can be sure you're right at the end of the animation.

Example:

When in a walking state, the player has an image_number of 6 and a speed of 8, and the room_speed is 60fps. So the check goes:

GML:
image_index >= 6 - 8 / 60
Or:

GML:
image_index >= 6 - 0.13
Or:

GML:
image_index >= 5.86
This way there's no risk of the animation getting chopped slightly early, it allows the 5th part of the animation to play out entirely.
 

Felbar

Member
I use a script called anim_end with this in it,
its not perfectly accurate because GML overflows the
fractional part of image_index when it rolls back to zero but in practice
I find its close enuff and doesn't clip the last frame too early
(this will only work if your image_speed > 0 , that is you are not playing the animation backwards)

GML:
var _frame_tick = sprite_get_speed(sprite_index) / game_get_speed(gamespeed_fps);

var _num_frames = sprite_get_number(sprite_index);

return image_index >= _num_frames - _frame_tick;
 
Last edited:
Bit late to the party but:

GML:
var last_frame_of_animation = image_number - sprite_get_speed(sprite_index)/room_speed;
image_index >= last_frame_of_animation;
This ensures that you are on the last frame of the last sub-image of the sprite animation.

image_index is the current sub-image of the sprite.
image_number is the total number of sub-images.
sprite_get_speed(sprite_index) returns the speed of the sprite as set in the GUI.
room_speed is the frame rate.

sprite_get_speed(sprite_index)/room_speed therefore returns the time increments that the image_index changes at. When you minus that from the image number you get the last frame of the last sub-image of the sprite animation. It is only when image_index is greater than or equal to that number that you can be sure you're right at the end of the animation.

Example:

When in a walking state, the player has an image_number of 6 and a speed of 8, and the room_speed is 60fps. So the check goes:

GML:
image_index >= 6 - 8 / 60
Or:

GML:
image_index >= 6 - 0.13
Or:

GML:
image_index >= 5.86
This way there's no risk of the animation getting chopped slightly early, it allows the 5th part of the animation to play out entirely.
I had to additionaly take 1 off the last_frame_of_animation to make it work for me like:

GML:
var last_frame_of_animation = image_number - sprite_get_speed(sprite_index)/room_speed;
return image_index >= last_frame_of_animation-1;
[CODE]
edit: I made a html5 game maker project it screwed some things up for me maybe it has something to do with html5 thing
 
D

DannySantos

Guest
I had to additionaly take 1 off the last_frame_of_animation to make it work for me like:

GML:
var last_frame_of_animation = image_number - sprite_get_speed(sprite_index)/room_speed;
return image_index >= last_frame_of_animation-1;
[CODE]
edit: I made a html5 game maker project it screwed some things up for me maybe it has something to do with html5 thing
Hmm that's really interesting. I'm surprised that the number that made it work was 1, would it not make more sense (if a minus number is needed at all, that it would be sprite_get_speed(sprite_index)/room_speed?

That's just me thinking out loud really, I don't have it open right now.
 
Top