GUI offset over characters/objects *SOLVED

Started by pixelincognito, Tue 21/11/2017 13:16:36

Previous topic - Next topic

pixelincognito

Thank you all in advance but I'm having an issue.

The set up-
My character enters a room and there are a number of enemies, when you attack or they attack (being turn-based), I display a simple GUI with a label in it that displays either damage caused or if the attack was a miss; a miss.

The GUI is displayed in the right place in the room I test my combat but when I move to another room (with different dimensions I may add) the GUI is in a totally wrong place.

Code: ags

gImpact.Visible=true;
aMiss.Play();
gImpact.SetPosition(object[0].X-9, object[0].Y-40);
lImpact.Text=String.Format("Miss!");


likewise when I want to move the gImpact GUI to the player I use a player.x-whatever, player.y-whatever and this also has the same affects as the displaying over the objects - it is correct in my test room but it isn't in other rooms of different dimensions player position. I thought that having a GUI set to the object.X and object.Y with a simple offsets would work fine regardless of the room size and where the objects are positioned in the room. I'm guessing I'm doing something wrong or that I'm not fully understanding how offsets work.

Any thoughts would be much appreciated as I'm trying to keep things as simple as possible.

Cheers

Snarky

Object and Character positions are in room coordinates. GUIs are in screen coordinates. Unless your screen is fixed at the top left corner of the room, the calculation will therefore be off. The solution is to subtract GetViewportX() from the Character or Object x-coordinate and GetViewportY() from the y-coordinate.

pixelincognito

ahh I thought it would be something like that...

Thank you so much.

Cheers.

SMF spam blocked by CleanTalk