SOLVED Subimage indices are clamped?

I was programming when I encountered a recurring, but still relatively 'surprising', effect: I have a 2-subimages sprite and whenever I ask GameMaker2 for the subimage '2' (the 3rd one), it shows me number '0' (the 1st one). Is this regular behavior, or should I clamp manually the subimage index?
// Example: 'spr' has 2 subimages and the following returns the same output:
draw_sprite(spr, 1, x, y);
draw_sprite(spr, 5, x, y); // Shouldn't this return an 'index out of range' error?

Thank you!


Hey, the sub images gets looped/cycled when the image index goes out of the range, you can say that this is the regular behavior... It is not necessary to manually clamp the subimage, unless required by something else on your code.


0,1,0,1,0 image=index
1,2,3,4,5 nth image

the 5th image should show image index 0 ... the first one


🐧 *penguin noises*
GMC Elder
The reason image_index does this is because of how the automatic animation works: when image_index is larger than the number of images, it is reduced by image_number (as many times as is necessary to get it within range) and thereafter an Animation End event happens.

Also, another quirk that's good to be aware of: automatic drawing always uses floor to round the subimage number, but manually drawing a sprite uses round instead (which rounds upwards at 0.5 and above). So there can be inconsistencies with certain animations if you draw sprites yourself unless you floor the subimage index (only really noticeable on animations that aren't intended to loop, like explosions).