image_index

The current sub-image being shown for the instance sprite.

Syntax:

image_index


Returns: Real


Description

A sprite is made up of one or more sub-images which can make the sprite appear animated as they switch from one to the other, or can they can be switched between in code to give different "states", much like a button has in windows. If the sprite is animated, then you can get the current frame of the animation by checking the image_index variable, or if you want to change the state of a static sprite, you can select a new sub-image by setting this variable to the desired sub-image for the sprite. Please note that for changes in this variable to be visible, the instance should have either no draw event (and so GameMaker: Studio will default draw the sprite) or be drawn using one of the extended drawing functions like draw_self() or draw_sprite_ext().

Please note that while using skeletal animation sprites, you can still get and set the image_index values - see the function skeleton_animation_get_duration for examples of how to do this.


Example:

if image_speed > 0
   {
   if image_index > image_number - 1 instance_destroy();
   }

The above code checks to see if the sprite is animating, and if it is it then checks to see if the current image_index is greater than the number of sub-images and if it is it destroys the instance.


Back: Instance Properties
Next: image_number
© Copyright YoYo Games Ltd. 2018 All Rights Reserved