sprite scaling with camera zoom

I'm trying to build a civ6-esque real time strategy game, and it should always have a mouse interactable menu on the screen. I have a menu sprite attached to an object that follows the camera around when the player moves it, but for some reason I can't get it to scale with the viewport when the camera zooms in and out. So, you zoom out from the map, but the menu shrinks like you're zooming away from it too. Here's the code I'm using, if anyone can tell me why it isn't working I'll be very grateful.

GML:
//obj_playerCamera create event

baseSpeed = 6;
cameraSpeed = 0;
minZoom = 1400;
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])

GML:
//obj_playerCamera mouse wheel up event

if (cameraW > minZoom)
    camera_set_view_size(camera, cameraW - (cameraW / 10), cameraH - (cameraH / 10));
GML:
//obj_playerCamera mouse wheel down event

if (cameraW < maxZoom)
    camera_set_view_size(camera, cameraW + (cameraW / 10), cameraH + (cameraH / 10));
GML:
//obj_ui create event

camStartWidth = cameraW;
GML:
//obj_ui step event

x = cameraX;
y = cameraY;
GML:
//obj_ui draw event

image_xscale = camStartWidth / cameraW;
image_yscale = image_xscale;
draw_sprite(spr_ui, -1, x, y);
To be clear, everything here works except for the image scaling
 
Before even attempting to resolve the issue, I have to ask... why aren't you using the Draw GUI event for these things? The GUI layer is independent of the cameras and so you never need to worry about scaling.

As for the issue, you're using the wrong draw_* function... You want this: https://manual.yoyogames.com/GameMa...Drawing/Sprites_And_Tiles/draw_sprite_ext.htm

;)
Holy cow. I can't help feeling a little sheepish that I've been trying to build a UI from scratch cause I didn't realize there was a whole layer/event dedicated to it. Thanks man haha
 
Top