sprite_duplicate

Creates a duplicate of the sprite with the given index.

Syntax:

sprite_duplicate(index);


Argument Description
index The index of the sprite to duplicate.


Returns: Real


Description

This function will return the index of a newly created sprite that is a duplicate (copy) of the one input as the "index" argument. If the function fails, -1 is returned. This function must be used to copy any sprites from the original assets before any transformations can be done on them. For example, if you wish to change the bounding box for a sprite, or set its alpha from another sprite, you must first duplicate it, then perform the operation on the duplicated sprite and use that.



NOTE: When you duplicate a sprite in GameMaker: Studio you must remember to remove it again (with sprite_delete) when no longer needed, otherwise there is risk of a memory leak which will slow down and eventually crash your game.


Example:

new_spr = sprite_duplicate(sprite_index)

The above code duplicates the sprite currently being used as the sprite index of the instance and stores the index for this new sprite in the variable "new_spr".


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