• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code Conflict between Draw GUI Objects, Viewports, and Gesture Commands

KishPrime

Member
I've been working on a 4X space game, and I have a clickable map that you can scroll around with GUI elements drawn on top via drawGUI events. I recently converted my buttons to use the tap gesture command, as I have an eye toward touch screen use in the future. However, the GUI buttons will not read the mouse tap.

I have tested it a variety of ways. The buttons work fine when not drawn via GUI, and they also work fine when the viewport is disabled. Is there a way to fix this, or is this a really strange hole in Gamemaker? Am I missing something obvious?
 

Yal

šŸ§ *penguin noises*
GMC Elder
Is the GUI layer size equal to the view size? (If you didn't change it manually, the answer is no). Since the GUI layer uses screen pixels, not window pixels, if you scale the window in any way, the GUI layer coordinates will get messed up. Use https://docs.yoyogames.com/source/d...e/windows and views/display_set_gui_size.html to set the GUI size to the size you're using (e.g. display_set_gui_size(view_wview,view_hview) in GMS1, I don't remember how to get the viewport size in GMS2 but you could just use macro constants for that).
 

KishPrime

Member
Is the GUI layer size equal to the view size? (If you didn't change it manually, the answer is no). Since the GUI layer uses screen pixels, not window pixels, if you scale the window in any way, the GUI layer coordinates will get messed up. Use https://docs.yoyogames.com/source/dadiospice/002_reference/windows and views/display_set_gui_size.html to set the GUI size to the size you're using (e.g. display_set_gui_size(view_wview,view_hview) in GMS1, I don't remember how to get the viewport size in GMS2 but you could just use macro constants for that).
Alright, so when I set the GUI size it now scales the GUI according to zoom. In my original code, the GUI elements remained in the positions I wanted them:

upload_2020-1-13_15-20-9.png

When changing the size, it changes the GUI with zoom change:
upload_2020-1-13_15-18-41.png

upload_2020-1-13_15-19-16.png

In neither scenario does the tap gesture work as soon as the camera is either moved or resized, so there's still a mismatch between the cursor position and the GUI position. My hard-coded functions for mouse clicking and overlap, etc, work fine, this is just coming from converting to the built-in event commands.
 

KishPrime

Member
If anyone stumbles onto this later, I simply ended up replicating out my own draw_gui function (based on some other code I found online) to calculate out placement myself. It appears that gesture commands are incompatible with the combination of draw_GUI and zooming viewports for now, and I haven't found anything to tell me differently after quite a bit of research.

// Get Camera Position
var cx = camera_get_view_x(view_camera);
var cy = camera_get_view_y(view_camera);
//make the adjustment to gui x,y
x = cx+GUI_x_position/global.zoomValue;
y = cy+GUI_y_position/global.zoomValue;
image_xscale = 1/global.zoomValue
image_yscale = 1/global.zoomValue
draw_self()
 
Top