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.
The easiest way is to put a button in the middle of the GUI and set the item sprite as the button graphic.
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
Thank you both.
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!
Thank you!