This function can be used to save any sub-image of any sprite to disc, giving it the specified filename. This image must be a *.png file.
NOTE: Depending on the target platform that is chosen you are limited as to where you can save and load files from. See File Handling for more information.
sprite_save(ind, subimg, fname);
Argument | Description |
---|---|
ind | The index of the sprite to save. |
subimg | The sub-image of the sprite to save. |
fname | The filename for the saved sprite. |
N/A
var surf, spr_custom;
surf = surface_create(32, 32);
surface_set_target(surf);
draw_clear_alpha(c_black, 0);
draw_sprite(spr_Body, 0, 0, 0);
draw_sprite(spr_Clothes, 0, 0, 0);
draw_sprite(spr_Hair, 0, 0, 0);
spr_custom = sprite_create_from_surface(surf, 0, 0, 32, 32, true,
true, 16, 16);
surface_reset_target();
surface_free(surf);
sprite_save(spr_custom, 0, "Player_Custom_Sprite.png");
sprite_delete(spr_Custom);
The above code creates a surface and stores its index in the local variable "surf". It then targets that surface, clears it and draws several sprites on top of each other. It creates a new sprite from the composite image drawn on the surface and assigns its index to the local variable "spr_Custom" before freeing up the memory used by the surface. Finally, the resulting sprite is saved to a file and then removed from memory too.