GameMaker Scaling issue when drawing to GUI layer.

T

Tom Jackson

Guest
Hey folks, trying to implement some text boxes into my game but have run into an issue when my camera zooms in and out.

At the moment my game will zoom in and out during cutscenes using both camera_set_view_size() and resizing the application surface using surface_resize()
e.g:
Code:
camera_set_view_size(view_camera[0], _width, _height);
surface_resize(application_surface, _width, _height);
This works fine but interferes with my textboxes which are drawn in the Draw GUI event.
The issue arises when trying to find the x and y coordinates of my currently talking npc relative to it's position in my view. The textboxes are connected to the characters that are speaking so I need their x and y values.
At the moment this is my code for finding said values:
Code:
var cam_x = camera_get_view_x(view_camera[0]);
var cam_y = camera_get_view_y(view_camera[0]);
var speaker_x = speaker.x - cam_x;
var speaker_y = speaker.y - cam_y;
This works fine when the camera's scale is 1-1, as an example:
speaker.x = 672
speaker.y = 242
cam.x = 600
cam.y = 200
So easily enough the npc's coordinates within my view are x = 72, y = 42.
Here's an example pic:
1.png


When zooming in things get a little beyond my grasp though as the camera's x and y position will move but the npc's won't.
In this example the npc is in the same position as the last example but the camera has zoomed in:
speaker.x = 672
speaker.y = 242
cam.x = 614
cam.y = 210
My code returns the wrong result now due to the moved position of my camera.
Example pic:
2.png

I've tried a few solutions including multiplying speaker.x & speaker.y by the camera's scaling amount and comparing the camera's default position to its zoomed position then applying that value as a scaling value but neither get the result I'm after.

Any help would be appreciated, happy to provide any code.
Thanks!
 
Last edited by a moderator:
Top