Skip to content

Instantly share code, notes, and snippets.

@attic-stuff
Created October 31, 2025 18:20
Show Gist options
  • Select an option

  • Save attic-stuff/5b6e923f1e7284ea1ae72485eda733a7 to your computer and use it in GitHub Desktop.

Select an option

Save attic-stuff/5b6e923f1e7284ea1ae72485eda733a7 to your computer and use it in GitHub Desktop.
takes a sprite frame, from stretched frames, and returns the image index for it
/*
* takes a sprite frame, from stretched frames, and returns the image index for it
* @param {Asset.GMSprite} sprite the sprite we're looking up
* @param {Real} frame the frame to check
* @return {Real}
*/
function sprite_get_index_from_frame(sprite, frame) {
var all_frames_information = sprite_get_info(sprite).frame_info;
if (is_undefined(all_frames_information) == true) {
return frame;
}
var index_count = sprite_get_number(sprite);
var this_frame_information = undefined;
var this_frame_number = 0;
var this_index_frame_length = 0;
for (var lookup_index = 0; lookup_index < index_count; lookup_index = lookup_index + 1) {
this_frame_information = all_frames_information[lookup_index];
this_frame_number = this_frame_information.frame;
this_index_frame_length = this_frame_number + this_frame_information.duration;
if (clamp(frame, this_frame_number, this_index_frame_length) == frame) {
break;
}
}
return this_frame_information.image_index + (frame - this_frame_number) / (this_index_frame_length - this_frame_number);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment