• 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!

Mouse Interaction

I

IndieCrypt

Guest
Hello,

I am in need of some help with some coding...

I need to animate my button so that when the mouse is hovering over the button it animates, I just cannot seem to get it to work... I am trying code like
Code:
if(mouse_x and mouse_y) = (x and y)
but it is not working... Any help would be great!
 

jo-thijs

Member
You should do it like this:
Code:
if mouse_x == x and mouse_y == y
What you wrote translates to:
if both mouse_x and mouse_y are true if and only if both x and y are true,
which isn't what you want.
 
I

IndieCrypt

Guest
You should do it like this:
Code:
if mouse_x == x and mouse_y == y
What you wrote translates to:
if both mouse_x and mouse_y are true if and only if both x and y are true,
which isn't what you want.
Thank you!
 

jo-thijs

Member
Actually, now I think of it, it is very hard to get mouse_x and mouse_y to equal an exact position.
To check whether your mouse is hovering over the executing instance, you should do this:
Code:
if position_meeting(mouse_x, mouse_y, id)
 
L

LudwigJaeck

Guest
To check if the mouse is hovering over a specific area use:
Code:
xhover = (mouse_x == median(x1,mouse_x,x2))
yhover = (mouse_y == median(y1,mouse_y,y2))

if(xhover&&yhover)
{
    //DO YOUR STUFF
}
 

jo-thijs

Member
That's one way to it, but what's wrong with:
Code:
if x1 <= mouse_x && mouse_x <= x2
&& y1 <= mouse_y && mouse_y <= y2 {
    // DO YOUR STUFF
}
 
L

LudwigJaeck

Guest
That's one way to it, but what's wrong with:
Code:
if x1 <= mouse_x && mouse_x <= x2
&& y1 <= mouse_y && mouse_y <= y2 {
    // DO YOUR STUFF
}
Nothing ? ;)
I guess he can use whatever he wants.
 
Top