Closeable Overlays

Started by paulmist, Tue 04/04/2023 09:38:58

Previous topic - Next topic

paulmist

Hi,

I'm trying to make an overlay that opens when you click on a hotspot and has its own close button.

My guess is I need some sort of GUI to open and be interactive as the overlay and possibly a dynamic placeholder for images I can load in for the varied hotspots.

The basic scenario is clicking on objects (say a piece of paper) and being able to see them close-up before closing them and continuing with the game.

Many thanks!

paulmist

On a side note, I asked Google Bard for a script and a few seconds later got the below. Does anyone have an opinion on it's validity or quality?

Code: ags
Sure, here is a script for Adventure Game Studio to open a GUI that contains a dynamic sprite:

```
#include "DynamicSprite.h"

void OpenGUI()
{
    // Create a new DynamicSprite object.
    DynamicSprite* sprite = new DynamicSprite();

    // Load the sprite image from a file.
    sprite->LoadImage("image.png");

    // Set the sprite's position on the screen.
    sprite->SetPosition(100, 100);

    // Set the sprite's size.
    sprite->SetSize(200, 200);

    // Add the sprite to the GUI.
    GUI.AddObject(sprite);
}
```

This script will create a new DynamicSprite object and load an image from a file into it. The sprite will then be positioned on the screen and added to the GUI. When the GUI is opened, the sprite will be displayed.

Snarky

#2
No, that is not valid AGS code. Both the logic, syntax and names of functions it calls are wrong. Neither Bard nor ChatGPT have had enough training to generate usable AGS code.

For your case, you can use either a GUI (with the background or a button set to the close-up sprite) or a graphical Overlay. Another option, if the close-up fills the whole screen, is to do each close-up as its own room—that way you can (more easily) allow the player to examine and interact with parts of the close-up.

Just try it out!

eri0o

AGS Script is very niche and these tools require way more data to learn.

They can't pounder about state very well, specially well defined and strict states, so in the very object oriented nature of AGS where all the things have their state they often spout non-sense.

Additionally, the context they operate when coding emanate solely from the code - they can't tell you to go to the editor and create a GUI, place a button, and name the button, link a function and then write the code for this button.

Overall, they are better used for purely creative purpose or helping with something that you can define well the expected input and output, even if you have to manually prepare the input data.

I would avoid using them when scripting for the time being, until you get more experience in AGS Scripting - the code is obviously wrong as even the grammar used is incorrect - there is no arrow operator in AGS Script, there is no include in AGS preprocessor, ...

paulmist

Thanks for the insightful and helpful comments - I'll continue to experiment and see what I can come up with. It's early days for me, but what a great tool.

As for the AI stuff, I don't intend on using it as I'd rather learn for myself - but it's interesting to see what comes up.

eri0o

Once you create a GUI in the Editor, and you name it, say gCloseup, you can show it by making it Visible.

Code: ags
gCloseup.Visible = true;

https://adventuregamestudio.github.io/ags-manual/GUI.html#guivisible

You can add a button in this GUI for closing in it, in the Editor, and name it, say btnCloseCloseup.

https://adventuregamestudio.github.io/ags-manual/EditorGUI.html#gui-buttons

In the events panel (⚡), you click on the on click event and it will write up a skeleton in the global script. There, actually closing the GUI is just making it not visible.

Code: ags
gCloseup.Visible = false;

Khris

You can make both the GUI and button as large as the screen, then set the GUI to be fully transparent and use a PNG with an alpha channel for the button.
This way you can have a button filling the entire screen with the close-up in the center and, say, semi-transparent black borders. That way the player can simply click anywhere to close the GUI again and you don't need to worry about clicks outside the close-up.

SMF spam blocked by CleanTalk