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

Discussion in 'GameMaker Studio 2 Community Tech Support' started by KishPrime, Jan 13, 2020.

  1. KishPrime

    KishPrime Member

    Joined:
    Jan 13, 2020
    Posts:
    4
    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?
     
  2. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    4,178
    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 likes this.
  3. KishPrime

    KishPrime Member

    Joined:
    Jan 13, 2020
    Posts:
    4
    I bet that is exactly what I needed. Thank you so much! Will test it later.
     
  4. KishPrime

    KishPrime Member

    Joined:
    Jan 13, 2020
    Posts:
    4
    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.
     
  5. KishPrime

    KishPrime Member

    Joined:
    Jan 13, 2020
    Posts:
    4
    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()
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice