Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Ghostlady on Thu 30/05/2024 21:43:18

Title: Center the background image in a gui
Post by: Ghostlady on Thu 30/05/2024 21:43:18
How do I center the background image in a gui?
When a player picks up an inventory item, I want the item to display in a gui. It works but not centered.
Title: Re: Center the background image in a gui
Post by: Snarky on Fri 31/05/2024 21:22:30
The easiest way is to put a button in the middle of the GUI and set the item sprite as the button graphic.
Title: Re: Center the background image in a gui
Post by: Crimson Wizard on Fri 31/05/2024 21:28:46
I recall there's a way to make this automatic. If you assign a magic button text "(INVNS)", then it should display active inventory item on its own.

https://adventuregamestudio.github.io/ags-manual/Button.html#buttontext
Title: Re: Center the background image in a gui
Post by: Ghostlady on Sat 01/06/2024 03:46:50
Thank you both.
Title: Re: Center the background image in a gui
Post by: Khris on Sat 01/06/2024 18:54:47
Here's another way:

DynamicSprite* invBG;

function ShowInvGUI(InventoryItem* ii) {
  GUI* gui = gInvItem; // GUI name here
  invBG = DynamicSprite.Create(gui.Width, gui.Height, true);
  DrawingSurface* ds = invBG.GetDrawingSurface();
  ds.Clear(COLOR_TRANSPARENT);
  ds.DrawImage((invBG.Width - Game.SpriteWidth[ii.Graphic]) / 2, (invBG.Height - Game.SpriteHeight[ii.Graphic]) / 2, ii.Graphic);
  ds.Release();
  gui.BackgroundGraphic = invBG.Graphic;
  gui.Visible = true;
}

You can now call this function in on_event, passing the item.

Untested!
Title: Re: Center the background image in a gui
Post by: Ghostlady on Wed 05/06/2024 04:59:36
Thank you!