Save a sprite to disc.


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.

Returns: N/A


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 Reference - Files for more information.


var surf, spr_custom;
surf = surface_create(32, 32);
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);
sprite_save(spr_custom, 0, "Player_Custom_Sprite.png");

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.

Back: Sprites
Next: sprite_save_strip
© Copyright YoYo Games Ltd. 2018 All Rights Reserved