D
Deleted member 16767
Guest
This is a paid job for my painting software. Please PM me if you know how to do this.
/// load_surface_gif(fname, removeback);
/// @param fname
/// @param removeback
/*
load a gif to a surface(s) [as many as there are frames in GIF]
*** MUST BE DONE IN DRAW EVENT
*** DO NOT RUN CONTINUOUSLY
*/
var _fname = argument0, /// GIF file
_remove = argument1, /// whether to remove background color (set alpha to 0)
_sprite = sprite_add(_fname, 1, _remove, false, 0, 0), /// sprite creation code
_surfArray = []; /// surface to transfer sprite to
//------------ calculate necessary surface size ----------//
var _w = sprite_get_width(_sprite), /// width of the surface
_h = sprite_get_height(_sprite), /// height of the surface
_qty = sprite_get_number(_sprite);
/// create surface(s)
for (var i = 0; i < _qty; ++i) {
_surfArray[i] = surface_create(_w,_h);
//------------ Transfer sprite to surface ----------------//
surface_set_target(_surfArray[i]);
draw_clear_alpha(c_black,0);
draw_sprite(_sprite,i,0,0);
surface_reset_target();
};
/// clean up sprite
sprite_delete(_sprite);
/// return array of surfaces
return(_surfArray);
gif_add_surface(gif_index, surface, delay_time, [xoffset], [yoffset]);
gif_save(gif_index, fname);
Unfortunately, sprite_add only loads first frame from the gif.Try this:
Also:GML:/// load_surface_gif(fname, removeback); /// @param fname /// @param removeback /* load a gif to a surface(s) [as many as there are frames in GIF] *** MUST BE DONE IN DRAW EVENT *** DO NOT RUN CONTINUOUSLY */ var _fname = argument0, /// GIF file _remove = argument1, /// whether to remove background color (set alpha to 0) _sprite = sprite_add(_fname, 1, _remove, false, 0, 0), /// sprite creation code _surfArray = []; /// surface to transfer sprite to //------------ calculate necessary surface size ----------// var _w = sprite_get_width(_sprite), /// width of the surface _h = sprite_get_height(_sprite), /// height of the surface _qty = sprite_get_number(_sprite); /// create surface(s) for (var i = 0; i < _qty; ++i) { _surfArray[i] = surface_create(_w,_h); //------------ Transfer sprite to surface ----------------// surface_set_target(_surfArray[i]); draw_clear_alpha(c_black,0); draw_sprite(_sprite,i,0,0); surface_reset_target(); }; /// clean up sprite sprite_delete(_sprite); /// return array of surfaces return(_surfArray);
And finally:GML:gif_add_surface(gif_index, surface, delay_time, [xoffset], [yoffset]);
GML:gif_save(gif_index, fname);
It gives a DoAdd error on a global variable I call gif. It's the "if gif < 0". I have the code for the gif already that someone did for me. It's a pretty big script with buffers and stuff (which I will not post here, because I paid for it).Most of the 2.2 stuff should port over well to 2.3. Or, are you trying to change the project structure?