Navigating fixed gui menu while also moving camera around

I'm trying to build a real time strategy game that involves the user clicking on a lot of menus while moving the camera around a map. It's all 2D, so the camera doesn't tilt, but it does zoom in and out to see the world better. I'm drawing a lot of menus with the Draw GUI event, which works great when the camera is in it's starting location, but as soon as the camera moves the mouse's x and y stop lining up with the gui's x and y coordinates and I can't click on anything.

I'm trying to build a converter that gives me the mouse's current coordinates on the screen rather than in the room, does anyone have any suggestions for how to do this?

When I'm just moving the camera and not zooming I figure I can just subtract the camera's coordinates from the mouse's coordinates, but as soon as I start incorporating zoom it gets tricky.

Here's a gif of the issue:

This is the code I'm using in the playerCamera object:

GML:
//create event

baseSpeed = 6;
cameraSpeed = 0;
minZoom = 1000;
maxZoom = 7000;

#macro camera view_camera[0]
#macro cameraX camera_get_view_x(view_camera[0])
#macro cameraY camera_get_view_y(view_camera[0])
#macro cameraW camera_get_view_width(view_camera[0])
#macro cameraH camera_get_view_height(view_camera[0])


// step event

if (!global.isPaused)      // can only move the camera when it's not paused
{
    cameraSpeed = round((cameraW / 1000) * baseSpeed);    // this keeps the camera's speed consistent despite the zoom level

    // basic keyboard controls
    if (keyboard_check(ord("D")) && cameraX < room_width)  
        camera_set_view_pos(camera, (cameraX + cameraSpeed), cameraY);
   
    if (keyboard_check(ord("A")) && cameraX > 0)
        camera_set_view_pos(camera, cameraX - cameraSpeed, cameraY);
   
    if (keyboard_check(ord("W")) && cameraY > 0)
        camera_set_view_pos(camera, cameraX, cameraY - cameraSpeed);
   
    if (keyboard_check(ord("S")) && cameraY < room_height)
        camera_set_view_pos(camera, cameraX, cameraY + cameraSpeed);
}


// mouse wheel up event

if (!global.isPaused)
{
    // this zooms the camera in by a tenth of the viewsize everytime the mouse wheel clicks
    if (cameraW > minZoom)
        camera_set_view_size(camera, cameraW - (cameraW / 10), cameraH - (cameraH / 10));
}


// mouse wheel down event

if (!global.isPaused)
{
   // this zooms the camera out by a tenth of the viewsize everytime the mouse wheel clicks
    if (cameraW < maxZoom)
        camera_set_view_size(camera, cameraW + (cameraW / 10), cameraH + (cameraH / 10));
}
How would you guys go about solving this issue?
 
Last edited:
Top