Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: glurex on Fri 14/04/2023 22:42:53

Title: Issue with various GUI Images
Post by: glurex on Fri 14/04/2023 22:42:53
Last year, I created a small silly game for MAGS in a few weeks. Although it wasn't my first game made with AGS, it was my first "published" game (now I'm working on two more titles). While watching the video that Stupot kindly recorded for the MAGGIES 2022, I realized (among other things that I have fixed now) something weird: in one of the rooms (Roman room), we have a board with many items that we have to find. As a hint system, I made it so that when the name of the object is clicked, an image of the item appears (and when the name is clicked again, it disappears). That image(s) is/are also a GUI, just like the item names on the board (yeah, a label would be better). However, I noticed that when someone clicks on another name (without clicking again to make the previous image disappear), the previous image remains and the effect is pretty awkward. I'd want that when one name is clicked and the previous image remains, that previous image dissapear before that make the other visible.

Here's the video (courtesy of Stupot) at 24:10:


I was thinking of possible solutions... maybe creating an array and assigning each item name (which is also a GUI) a position in the array. But I can't find a way to do it.


Thanks!
Title: Re: Issue with various GUI Images
Post by: Crimson Wizard on Fri 14/04/2023 22:57:16
How do you display these images exactly, in AGS terms? Why cannot you check whether *some* image is already displayed and remove it before displaying another one?
Title: Re: Issue with various GUI Images
Post by: glurex on Fri 14/04/2023 23:38:08
Quote from: Crimson Wizard on Fri 14/04/2023 22:57:16How do you display these images exactly, in AGS terms? Why cannot you check whether *some* image is already displayed and remove it before displaying another one?

I was a bit more inexperienced when I did that game so: all the 15 names in the board are, each one, a button GUI (example: Button6/Helmet). When I click that button GUI another GUI (that contains the image, gHelmet) is set to visible=true. For example:

function Button6_OnClick(GUIControl *control, MouseButton button)

{
if (onoff==0) //to check the mouse click
  {
gHelmet.Visible=true; //the hint image displayed
onoff=1;
  }
  else if (onoff==1)
  {
    gHelmet.Visible=false;
    onoff=0;
    }

As far they are 15 image GUIs (gHelmet, gRabbit, gDeet, and so on) and therefore 15 Button GUIs, I can't find a reliable way to do what you said (check whether *some* image is already displayed and remove it) without writing too many lines of code. I'm sure I'm missing something.
Title: Re: Issue with various GUI Images
Post by: Crimson Wizard on Fri 14/04/2023 23:53:32
If only 1 image is supposed to be on screen at the same time, then the easiest way here would be to have 1 GUI, and change its BackgroundGraphic. This way you always know if GUI with an image is visible, and which image is that.
Title: Re: Issue with various GUI Images
Post by: glurex on Sat 15/04/2023 00:09:50
Quote from: Crimson Wizard on Fri 14/04/2023 23:53:32If only 1 image is supposed to be on screen at the same time, then the easiest way here would be to have 1 GUI, and change its BackgroundGraphic. This way you always know if GUI with an image is visible, and which image is that.

Fantastic! Works like a charm, sometimes I tend to overcomplicate things  :-D
Title: Re: Issue with various GUI Images
Post by: Khris on Sun 16/04/2023 14:38:07
Just in case a situation arises where one has to use multiple GUIs:
if they have consecutive numbers, you can simply do
  for (int i = 6; i <= 12; i++) gui[i].Visible = false;to turn them all off before turning on the one related to the button.