layer_sprite_index

This function can be used to set the image index of a sprite asset which has multiple sub-images on a layer. You give the sprite element ID (which you get when you create a sprite element using layer_sprite_create() or when you use the function layer_sprite_get_id()), and then set the image index to use. If you set a value outside of the range of sub-images, then the image index will loop around.

 

Syntax:

layer_sprite_index(sprite_element_id, image_index);

ArgumentTypeDescription
sprite_element_idSprite Element IDThe unique ID value of the sprite element to set
indexRealThe image index to use for the sprite

 

Returns:

N/A

 

Example:

var lay_id = layer_get_id("sprite_trees");
var spr_id = layer_sprite_get_id(lay_id, "gfc_trees");
layer_sprite_index(spr_id, 1);

The above code will get the layer ID for the layer named "sprite_trees" and then use that to get the ID of the given sprite element on that layer. This ID is then used to change the element image index.