image_index - currently displayed subimage of a sprite
( Game Maker 6.1, 7 )
Explanation
image_index is an object variable that contains the currently displayed subimage of a sprite. The first subimage of a sprite is 0.
Examples
If you have a single sprite with one subimage looking right, and one subimage looking left, you can use the image_index variable to change it at your will. Usually, when you use the image_index variable, you want to set the image_speed to 0.
Set image_index
Say one sprite holds the following images: a standing, a crouching and a running image. Then, in the Down Key event, you could put the following code to make the character crouch (assuming it is subimage 1):
image_index = 1;
Again, this is assuming the image_speed is set to 0.
image_speed
image_speed adds whatever number is assigned to it to the image_index every step event. You could replicate this effect by adding 1 to the image_index every step, or whatever number you need. The image_speed variable usually will suffice, though.
Rounding
If the image_index is set to a non-whole number, it will round down. For example, image_index = 0.5 will set the image_index to 0.5 for further reference, but will display sub-image 0.
Related Pages
Actions That Can Change image_index
Other
- image_speed — animation speed of the sprite of an instance
- sprite_index - index of the sprite of an instance
| Categories: GML : Graphics : Local Variables : Sprites : Variables |