Stop GUI from moving with the camera

Started by Fedx, Thu 07/05/2020 22:18:36

Previous topic - Next topic

Fedx

Hello! I have a question of how I can make a GUI stop moving with the game camera. I have a room where you are watching from outside in with a flashlight, in between the holes of some planks. I made the planks as a GUI so the flashlight can be behind, and I also made a camera that follows the mouse, since the room is bigger than the game's resolution and you have no character to explore it. This is my code right now

Code: ags
function room_Load()
{
  gSky.Visible = false; //Make the sky from the previous room not visible
  gPlanks.Visible = true; //Make the planks visible
  gFlashlight.Visible = true;
  mouse.Mode = eModeUsermode1; //Change mouse to flashlight
  Game.Camera.Create();
  Game.Camera.AutoTracking = false;
}

function hVolver_AnyClick()
{
  cJoseph.ChangeRoom(11, 189, 293); //Clicking anywhere to go back
}

function room_RepExec()
{
  gFlashlight.SetPosition(mouse.x-640, mouse.y-640); //Positioning the flashlight GUI
  Game.Camera.SetAt(mouse.x, mouse.y); //Making the camera following the mouse
}


What happens is that the planks are always following the camera, and I want it to stay stationary. I've tried using another camera and viewports, set the position as x=0 and y=0, but still, it keeps on moving. What could I do? Thanks a lot!
- The gamer doesn't dies... he respawns -

Crimson Wizard

#1
I'd like to clarify, GUI does not follow camera, it simply stays on same position on screen, guis and cameras are not related (cameras only apply to what's inside the room, and guis are not in room, they are "on screen", so to speak).

What you need to do is opposite, move GUI in sync with the room visual position, which is opposite to the camera movement:
Code: ags

gPlanks.X = -Game.Camera.X;
gPlanks.Y = -Game.Camera.Y;

above code should be in rep-exec function.

Also, I noticed that you are setting camera coordinates incorrectly.
Code: ags

Game.Camera.SetAt(mouse.x, mouse.y); //Making the camera following the mouse


This won't work properly, because camera's position is set in room coordinates, and mouse position is in screen coordinates. What you need is to first convert between mouse and room coordinates:
Code: ags

Point* p = Screen.Viewport.ScreenToRoomPoint(mouse.x, mouse.y);
Game.Camera.SetAt(p.x, p.y); //Making the camera following the mouse



There are two coordinate systems in AGS: screen coordinates and room coordinates. GUI, mouse, text messages - they are "on screen" and positioned in screen coords, while room objects, areas and characters are inside the room and so have room coordinates.



PS. To be honest, I doubt GUI makes a good substitute for object. Have you tried making planks a room object with lower baseline to keep it above flashlight?

SMF spam blocked by CleanTalk