Center the background image in a gui

Started by Ghostlady, Thu 30/05/2024 21:43:18

Previous topic - Next topic

Ghostlady

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.
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

Snarky

The easiest way is to put a button in the middle of the GUI and set the item sprite as the button graphic.

Crimson Wizard

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

Ghostlady

My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

Khris

Here's another way:

Code: ags
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!

Ghostlady

My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

SMF spam blocked by CleanTalk