Legacy GM Loading GIF as Sprite from Filename

Posho

Member
Hello,

I'm trying to load multiple animated GIF files from a directory. According to the manual, the function sprite_add only loads the first frame of the GIF.

Is there any workaround method for this?
 

wlacie

Member
I solved this by writing a bash script that uses ImageMagick to turn all the GIF files in a directory into spritesheets (PNG strips). The tricky thing though is that my GIF files often dont have the same number of frames.
I'm gonna try to have my bash script discover the number of frames in the GIF before converting it to a PNG strip and then add that number to the end of the filename. ie. foobar-14.png. When using sprite_add i can hopefully read the filename, split it on "-" to grab the number of frames.


Something like this:

// foobar-14.png

var file_info= string_split(filename, "-");
var frames = file_info[1]; // 14

spr = sprite_add(working_directory + "STRIPS/"+fileName, frames, true, true, 0, 0);
 
Last edited:

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
I solved this by writing a bash script that uses ImageMagick to turn all the GIF files in a directory into spritesheets (PNG strips). The tricky thing though is that my GIF files often dont have the same number of frames.
I'm gonna try to have my bash script discover the number of frames in the GIF before converting it to a PNG strip and then add that number to the end of the filename. ie. foobar-14.png. When using sprite_add i can hopefully read the filename, split it on "-" to grab the number of frames.


Something like this:

// foobar-14.png

var file_info= string_split(filename, "-");
var frames = file_info[1]; // 14

spr = sprite_add(working_directory + "STRIPS/"+fileName, frames, true, true, 0, 0);
If you're going that route, you might as well use ImageMagick to combine the images into a horizontal strip with "*" syntax (just make sure to clean up the frames beforehand).

A few days ago I updated my GIF loader to work in GMS1 as well, though I'm fairly sure that invoking IM would be faster for large GIFs.
 
Top