GML: sprite_index

sprite_index - currently displayed sprite.

( Game Maker 6.1, 7 )

Explanation

sprite_index is a local object variable that contains the name of the currently displayed sprite of that object. It can be used to set or change the sprite of an object.

When using sprite_index keep in mind that a sprite in Game Maker can have several subimages. If you want to set a specific image to be displayed, also use image_index.

Whenever you need to change the sprite, for example, to make a character face left or right, you can change the sprite_index depending on another variable which indicates which way a game object or character is facing.

Examples

Change the Sprite of an Instance

The GML code below will change the sprite of an instance from it's current sprite to spr_other_sprite.

sprite_index = spr_other_sprite;

Related Pages

Actions

GML

Categories: GML : Graphics : Sprites : Variables