This variable returns the current sprite set for the instance, or -1 if the instance has no sprite associated with it.
You can change it to give the instance a different sprite, by either giving it the reference of a sprite from The Asset Browser or by using a variable that has an externally loaded sprite indexed in it.
Changing the sprite does not change the index of the currently visible frame, given that there is a sub-image for the current frame in the new sprite. So if you change the sprite on frame number 3, the new sprite will be drawn with that frame visible. However, if the new sprite does not contain a sub-image for the current frame, image_index will reset to 0, displaying the first frame of the sprite instead.
sprite_index;
with (obj_Check)
{
if !collision_line(x, y, other.x, other.y, obj_Wall, false, true)
{
sprite_index = spr_spotted;
}
else
{
sprite_index = spr_clear;
}
}
The above code will loop through all instances of "obj_Check" checking for a collision line between them and the instance running the code. The sprite of those instances will be changed depending on the return value (true or false) for the collision line.