Gui Button changes its graphic permanently when mouse is over

Started by AnasAbdin, Sun 28/12/2014 08:58:30

Previous topic - Next topic

AnasAbdin

Hi all,
The title says it all. I'm trying to make a GUI button changes its graphic to another sprite when mouse is over, making sure it won't change back to it's normal graphic when mouse moves away.

Many thanks in advance :)

Slasher

Hi,

if you want to change a buttons graphic when mouse over you could add this in global rep exec:
Code: ags
 
 // change the gui / button script name etc for your game
 if((mouse.x >Button48.X+gHealth.X)&&(mouse.x <Button48.X+Button48.Width+gHealth.X)){ 
 if((mouse.y >Button48.Y+gHealth.Y)&&(mouse.y <Button48.Y+Button48.Height+gHealth.Y)){
 if(Button48.NormalGraphic==519){
 Button48.NormalGraphic=510;
}
}
}


This should work and the button graphic will not return.


AnasAbdin

Thanks slasher. It worked :)
I've placed the code in the room's rep exec though. I was hoping if there was another way other than using the mouse's xy but I guess I'll stick to this method for the time.

Slasher

Hi AnasAbdin,

QuoteIt worked
I'm glad to hear it ;)

The reason I use the code that way is that all the buttons on my gui are positioned at random.



Monsieur OUXX

A more elegant solution for mouse-over event would be :
Code: ags

// in repeatedly_execute_always
if (GUIControl.GetAtScreenXY(mouse.x, mouse.y) == Button48) {
    //change graphic permanently with .NormalGraphic, as shown by slasher
}

 

AnasAbdin

Quote from: Monsieur OUXX on Sun 28/12/2014 15:43:25
A more elegant solution for mouse-over event would be :
Code: ags

// in repeatedly_execute_always
if (GUIControl.GetAtScreenXY(mouse.x, mouse.y) == Button48) {
    //change graphic permanently with .NormalGraphic, as shown by slasher
}



Thanks Your Excellency (roll)

SMF spam blocked by CleanTalk