Context Menu over chatacters head.

Started by jamesreg, Sat 23/02/2019 17:37:19

Previous topic - Next topic

jamesreg

I am trying to figure out how to when using the intetact Icon on the player chatacter or any other non player chatacter to get it to open a gui menu above his head.

Crimson Wizard

#1
Converting character's (room) coordinates to screen coordinates looks like this (pre-3.5.0 code)
Code: ags

int x = somechar.X - GetViewportX();
int y = somechar.Y - GetViewportY();


but these are coords of character's feet, so we need an adjustment by their height. This may be done in various ways including defining a constant or using a custom property, but you may also need to check for walkable area's zoom

Code: ags

// Variant with getting current frame sprite (not necessarily the best one since sprite heights may vary depending on pose)
ViewFrame* vf = Game.GetViewFrame(somechar.View, somechar.Loop, somechar.Frame);
int original_height = Game.SpriteHeight[vf.Graphic];

// Variant with custom properties
int original_height = somechar.GetProperty("MyHeight");

// Applying walkable area scale
int zoom = GetScalingAt(somechar.X, somechar.Y);
int real_height = original_height * 100 / zoom;


And in the final:
Code: ags

// Showing GUI above the head:
int gui_center_x = somechar.X - GetViewportX();
int gui_bottom_y = somechar.Y - GetViewportY() - real_height - some_hardcoded_margin_maybe;


This is very basic example of course, because in real life your character could be standing near the top of the screen, in which case you may need an algorithm to move GUI lower.

SMF spam blocked by CleanTalk