Gui areas with different functions [SOLVED]

Started by nightmarer, Mon 15/06/2020 10:20:01

Previous topic - Next topic

nightmarer

Hello everybody.

I would like to use this GUI for the player

2-escala" border="0

What I want to make is to make able different functions depending if you press "B" or if you press "m", but seems that if you dont use buttons already provided by AGS it is not that easy.
It is possible to establish regions in anyway in the GUI?

Regards.

Slasher

#1
Normal GUI buttons are within a rectangle around them so odd shapes are awkward to enforce.

You could make those buttons un-clickable and make 2 more smaller transparent buttons (bring to front) that sit inside those main buttons where its these new buttons that run events.

Food for thought..

Laura Hunt

Quote from: nightmarer on Mon 15/06/2020 10:20:01
but seems that if you dont use buttons already provided by AGS it is not that easy.

You aren't limited to the default ugly grey background, though. If you have your "M" and "B" as separate sprites with transparent backgrounds, you can set those as the image for your buttons. Create a button, go to the Properties panel, look for "Image", assign your sprite there, and the button will resize itself automatically to the size of your sprite. That should do it!

Khris

1. Split that sprite in two, one for each button
2. Add button B to the GUI and assign it the B sprite
3. Add button M to the GUI and assign it the M sprite (place it at exactly the same position as button B)
4. Add this to the global repeatedly_execute:
Code: ags
  if (gMB.Visible) {
    int x = mouse.x - gTest.X - btnM.X;
    int y = mouse.y - gTest.Y - btnM.Y;
    btnM.Clickable = y < x - 5;
  }


(since button M is added later, it covers button B; by setting it to non-clickable if the mouse is over the B half, both buttons can be clicked despite occupying the same space on the GUI)

Laura Hunt

Oh, I see! I think I totally misunderstood the question, because I was assuming that only the letters M and B should be clickable, not the whole surface of each red/blue half. Clever :)

Snarky

Or just have one button and put Khris's test in the OnClick() function to decide what should happen:

Code: ags
function btnMB_OnClick()
{
  int x = mouse.x - gTest.X - btnM.X;
  int y = mouse.y - gTest.Y - btnM.Y;
  if(y < x - 5)
  {
    // Clicked M
  }
  else
  {
    // Clicked B
  }  
}


(This doesn't work so well if you want different hover or button-depressed effects, though.)

nightmarer

Thank you all!!
Finally this is what it worked.

Code: ags
function gCast2_OnClick(GUI *theGui, MouseButton button)
{
 int x = mouse.x - gCast2.X;
 int y = mouse.y - gCast2.Y;
 if(y <= x)  {
  Display("M");
 }
 else {
  Display("B");
 }  
} 

:grin: :grin:

SMF spam blocked by CleanTalk