sprite_delete

This function will delete a sprite from the game, freeing any memory that was reserved for it. This is a very important function for those moments when you need to create and change sprites from external sources (like loading a sprite from a file with sprite_add(), or duplicating a sprite using sprite_duplicate()) and should always be used to remove those assets that are no longer needed by a game, or to clear an indexed asset from a variable before re-assigning another asset to that variable.

IMPORTANT This cannot be used to delete sprites that are included in the game as part of the assets in the Asset Browser.

This function will return true if the sprite was successfully deleted, or false in case of an invalid sprite (e.g. it was already deleted).

 

Syntax:

sprite_delete(index);

Argument Type Description
index Sprite Asset The index of the sprite to be deleted.

 

Returns

Boolean

 

Example:

var spr = sprite_create_from_surface(application_surface, 0, 0, 32, 32, false, false, 16, 16);
sprite_merge(spr_Player, spr);
sprite_delete(spr);

The above code creates a local variable and then stores the index of the sprite created from the application surface. This sprite is then merged with the asset indexed in the variable "spr_Player" before being removed from memory again.