• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Help with animation

popley303

Member
Hello, I have a sprite that has 6 sub images. I am trying to get it so the when the mouse hovers over a button that it displays the images 0-6. I was just using 1 sub image and that was easy to get working i used the following code:


in mouse enter event:

image_index = 1;

and in the mouse leave event:

image__index = 0;

That would make it so my image would change from image 0 to 1 when hovering over the button. I decided to make 5 more sub images and tried to use the following:

in mouse enter event:

image_index = 6;

which would in turn change from image 0 to 6 without going through 0 to 6. I am trying to make it so it shows image 0,1,2,3,4,5,6 when hovering over the image.

Please help, thank you in advance.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Here's how I'd do it:
GML:
// CREATE EVENT
image_speed = 0;
image_index = 0;

// STEP EVENT
if point_in_rectangle(mouse_x, mouse_y, bbox_left, bbox_top, bbox_right, bbox_bottom)
{
if image_index < image_number -1
    {
    image_index += 1;
    }
}
else
{
if image_index > 0
    {
    image_index -= 1;
    }
}
All this is doing is checking if the mouse is within the bounding box of the button (the same as the mouse over event does, only using code so you have more control), and if it is, it increments the image_index until it reaches the last frame, and if it's not, it decrements the image_index until it reaches 0.
 
Top