Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Gepard on Sat 03/08/2013 19:42:13

Title: GUI above an object/character
Post by: Gepard on Sat 03/08/2013 19:42:13
Hello there? Is there a way to move a GUI on top of a character or an object? By default if you use Move (char.x, char.y), it will be moved to its "feet". Is there a way to move it above its "head"? All my objects and characters are of different size so I cannot move guis like (char.x - 10).

Thanks!
Title: Re: GUI above an object/character
Post by: monkey0506 on Sat 03/08/2013 19:57:15
You could try setting the BlockingWidth and BlockingHeight properties for each Character and Object, although that has to be done on a per-character basis in the script, and it's prone to error if certain things change. Getting the current height of a character is pretty simple though:

Code (ags) Select
// GlobalScript.ash
import int GetHeight(this Character*, bool scaled=true);

// GlobalScript.asc

int GetHeight(this Character*, bool scaled)
{
  ViewFrame *currentFrame = Game.GetViewFrame(this.View, this.Loop, this.Frame);
  int height = Game.SpriteHeight[currentFrame.Graphic];
  if (scaled) height = ((height * this.Scaling) / 100);
  return height;
}


With this you could then position your GUIs like:

Code (ags) Select
gEgoStats.SetPosition(cEgo.x - (gEgoStats.Width / 2), cEgo.y - cEgo.GetHeight() - 10);

Of course you'd want to do bounds checking and so forth. Getting the character width is the same principle, just using Game.SpriteWidth instead. You already mentioned it, but just bear in mind that (Character.x, Character.y) refers to the bottom-center of the Character, whereas (GUI.X, GUI.Y) refers to the top-left. If you want or needed to, you could easily devise a simple function to position the GUI to different alignments as well (left-aligned to character image, centered, right-aligned, above, below, etc.).
Title: Re: GUI above an object/character
Post by: Gepard on Sun 04/08/2013 15:47:02
Wow! Thanks for your reply. This looks a bit difficult but I will give it a shot.