GameMaker Studio 2 - Object changes to different sprite without programming (GML)

1k Views Asked by At

While programming my game, I came up on a significant issue. I am trying to create a tactical game, and I created grid cell objects for it. In the object's step event, it has the following code to change the sprite index when the mouse hovers over it.

if (position_meeting(mouse_x,mouse_y,OBJ_GridCell))
{
    sprite_index = 1;
}
else
{
    sprite_index = 0;
}

This is what the intended sprite looks like (set in object properties):What the sprite should look like.

But then when I run the game, it changes to another sprite I have, and the code functions like it should. It just is the wrong sprite. The output.

I have tried searching, but I can't find anything that matches my issue. Help?

1

There are 1 best solutions below

1
On BEST ANSWER

Looks like you want to pick a different frame inside a sprite, so you should use image_index instead of sprite_index.

image_index decided which frame in the sprite will be picked, where sprite_index let you choose a different sprite.