GUI above an object/character

Started by Gepard, Sat 03/08/2013 19:42:13

Previous topic - Next topic

Gepard

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!
Drink up me 'arties! Yo ho!

monkey0506

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
// 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
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.).

Gepard

Wow! Thanks for your reply. This looks a bit difficult but I will give it a shot.
Drink up me 'arties! Yo ho!

SMF spam blocked by CleanTalk