• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

[SOLVED] image_index gives decimal values???

Game Maker Studio 1.4.1753

When running a game and checking image_index in the step event of an object, I get a decimal value as an image index? How can that be? I cannot have 0.2 of an index in a sprite that has 6 images??? I attached a picture of the dubugger as a proof. Can someone clear this out to me?.


Last edited:
That's perfectly normal behaviour. If you set 0.2 as image_speed the image_index will increment 0.2 every step, it displays the next subimage on every integer (round value). So it starts on 0 with the first subimage, then on 1.00 it will switch to the 2nd image, on 2.00 to the 3rd image, and so on. Otherwise, how could you have an image_speed of 0.2 if it was impossible to have decimals in image_index?


🍋 *lemon noises*
GMC Elder
Actually, it can be worth noting that draw_sprite() and its derivatives rounds the image value, so these will use the second image for image_indexes between 0.5 and 1.5. I'm not sure what draw_self() and empty draw events call, but I think they floor the image instead, i.e. round downwards. Being aware of this helps synchronizing drawing, but it's generally not a concern. (In some cases where you manually animate a sprite with several animations in the same sprite, or in animations that doesn't loop such as explosions, you will notice 'bleed' if you don't plan for this case, though)
I knew people would tell me about image_speed but that's certainly not the point in using image_index. For example:
if (image_index = 3)
  // Do something
That always worked as I make several games that work with image index, for example, a rotating sprite. So comparing an integer to a decimal image_index will always return false. I'm basically pointing out that I think GMS should rethink their image_index returned value as it should ALWAYS return which image is currently used by the object.

Here is the documentation for image_index: https://docs.yoyogames.com/source/dadiospice/002_reference/objects and instances/instances/instance properties/image_index.html

A decimal valued image does not exists and therefor should not be returned by image_index.
This may shed some light. It also means it's unlikely to be changed.
With that argument, my cat is dead. I've been using this function for years but never encountered this type of problem before. I still think that GMS should NOT return a real number but a rounded down number for image_index as this is more usefull than using those decimal values as image_index is only there to tell us which subimage is currently drawn. But at least, I have my answer, I'll need to change my scripts from now on with this solution:
  • floor(image_index).
Thanks for the doc Jezla! That cleared a few things that I was unaware. After all those GM years, I tend to take some old stuff for granted that I should not.