Problem with image_index - Animations

Posted by diomatics
The other player object won't reset the image_index back to 0 after I stop the run animation. However, image_speed seems to work fine.

Why doesn't image_index apply to the other player?

Replies (8)

Last message on 9 Dec 2018

jdev on 6 Dec 2018, 15:14:49
Basic variables such as image_index and image_speed should automatically sync. Please could you show your code for this specific instance of events?
diomatics (Topicstarter) on 9 Dec 2018, 00:44:16

Thanks for your reply.

I have a lot of code, so I don't know how to show it properly. It it just a basic movement script. If the hspeed == 0 the image_speed and image_index will be set both to 0.
Is there a other/better way to handle it?

It is only the image index which is not working (strangely).
Again, it works fine with the normal player...
jdev on 9 Dec 2018, 02:00:14
When you put code like that into your obj_player, it should automatically work in the obj_other_player.

I would need to see your code to continue to debug the situation effectively.
diomatics (Topicstarter) on 9 Dec 2018, 13:56:56
I have a keyboard event that adds 1 to debug when pressed, so that I can cycle through the animation.

sprite_index = s_player;

if (debug > 0)

image_index = debug;


image_index won't work, no matter how I use it... but why?
jdev on 9 Dec 2018, 15:21:54
OK, so image_index is for the frames in a sprite_sheet, so if you only have 1 frame in your player sprite_sheet, then it will just return false and not work.

If you have a walking animation, your image_index could be set to the (for example) 3rd frame, which would be image_index = 2 (which could be your idle frame in the sprite sheet.

sprite_index is for changing your sprite's index to that of another, so you can change it to a completely different sprite.
jdev on 9 Dec 2018, 15:23:57
To add on, if you have already set the sprite of the obj_player using the build in GM:Studio systems, you do not need to put "sprite_index = s_player" in your code anywhere, as that will just cause issues.
diomatics (Topicstarter) on 9 Dec 2018, 16:29:24
Okay, I will completly re-write my project just to have it more clear.

Thank you!
jdev on 9 Dec 2018, 17:34:43
No problem! Let me know if you have any more issues.