• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Convert Normal X and Y to GUI X and Y

B

BloodCorn

Guest
Hi,
My gui layer is a different size to my application_surface and I was wondering if there was a way to convert the normal x and y coords to be in the same spot on the screen when drawn in the gui layer. Any help would be much appreciated.

Thanks,
BloodCorn
 
Here's how I'm doing it:

Code:
        var cl = camera_get_view_x(view_camera[0])
        var ct = camera_get_view_y(view_camera[0])
       
        var off_x = x - cl // x is the normal x position
        var off_y = y - ct // y is the normal y position
       
        // convert to gui
        var off_x_percent = off_x / camera_get_view_width(view_camera[0])
        var off_y_percent = off_y / camera_get_view_height(view_camera[0])
       
        var gui_x = off_x_percent * display_get_gui_width()
        var gui_y = off_y_percent * display_get_gui_height()
 
B

BloodCorn

Guest
Unfortunately this code does not work, do you have any ideas as to why?
 
Please be more specific.

How did you adapt the code I posted into your game.

In what way is it not working?

What error messages did you get, if any?

To be fair, I was in a rush, so didn't make time to post an explanation of the code.

It's basically grabbing the location of the top left position of the screen(cl, ct), working out the percentage of the offset from that corner to the object in screen space(off_x_percent, off_y_percents), then multiplying those percentage values by the size of the gui to give the same relative position(gui_x, gui_y).
 
B

BloodCorn

Guest
What is happening is the text is being drawn not in center when it is in fullscreen but center when it isn't? Do you think this is an aligning issue?
 

GMWolf

aka fel666
If your view rotates, etc:
Assuming a normal 2D setup:
Get your view matrix (either from Camera, either using matrix_get)
Transform your pp int using matrix_tranform_vertex

Done!

Assuming some weirder setup:
Multiply the view, world, and projection matrices together.
And then use matrix_transform_vertex with that.
 
What is happening is the text is being drawn not in center when it is in fullscreen but center when it isn't? Do you think this is an aligning issue?
Are you using the function display_set_gui_size() anywhere in your game?

Without seeing your code, the behaviour you describe sounds like you have hard-coded your x and y values, and when you are going into full-screen mode, you are re-sizing your gui, which would make the x and y values for drawing in the gui incorrect.

But this is just a guess.

You really need to provide more info, instead of me trying to extract it :)

Please post the code you are using for drawing whatever it is you are drawing to the screen, and any relevant code that you are using when re-sizing / going full screen etc...
 
B

BloodCorn

Guest
I do not use matrixs in my game at all.

Are you using the function display_set_gui_size() anywhere in your game?
Yes I am here is the code:
Code:
/// @description GUI Size
var wh = window_get_height();
globalvar aspect_ratio;
aspect_ratio = 16/9;

gui_scale = ((720*aspect_ratio)/(wh*aspect_ratio));

width = (wh*aspect_ratio)*gui_scale;
height = wh*gui_scale;

display_set_gui_size((wh*aspect_ratio)*gui_scale,wh*gui_scale);
display_set_gui_maximise(1, 1, 0, 0);
in my draw begin code


I hope this helps!
 

GMWolf

aka fel666
I do not use matrixs in my game at all.
do you use cameras? if so, the easiest solution is the matrix one. (because it works in pretty much all situations)

[edit] Oh wait, with GUI as well? That's trickier. I would first convert to view space, then to GUI.
The last step may be the most difficult one since there isn't really a "1-1" mapping.
 
Last edited:

toxigames

Member
This may be a dumb question: But can't you just set GUI layer to the same size as your view?

display_set_gui_size(view_hview, view_wview);
 
B

BloodCorn

Guest
This may be a dumb question: But can't you just set GUI layer to the same size as your view?
My game is centred around text so I maximise the gui space to make it better for more resolutions.

do you use cameras? if so, the easiest solution is the matrix one. (because it works in pretty much all situations)
I have no idea about matrixes - is there any good place to start?
 
Yes I am here is the code:
Code:
/// @description GUI Sizevar wh = window_get_height();globalvar aspect_ratio;aspect_ratio = 16/9;gui_scale = ((720*aspect_ratio)/(wh*aspect_ratio));width = (wh*aspect_ratio)*gui_scale;height = wh*gui_scale;display_set_gui_size((wh*aspect_ratio)*gui_scale,wh*gui_scale);display_set_gui_maximise(1, 1, 0, 0);
in my draw begin code
As an optimisation tip, I would only call this code when the window size changes, instead of re-sizing the gui layer every frame.

What exactly is it you are trying to achieve? There might be a better way to do this, but would need to know what you are attempting to do.

For example, are you trying to draw health bars above enemies, except draw them on the gui layer? If so,why aren't you just drawing the in the standard draw event.
 
B

BloodCorn

Guest
Ok, I am trying to make menu buttons with the button in the normal layer and the text in the draw gui because if the text is on the normal draw layer it gets distorted and blurry.
 
Here's how I'm doing it:

Code:
        var cl = camera_get_view_x(view_camera[0])
        var ct = camera_get_view_y(view_camera[0])
      
        var off_x = x - cl // x is the normal x position
        var off_y = y - ct // y is the normal y position
      
        // convert to gui
        var off_x_percent = off_x / camera_get_view_width(view_camera[0])
        var off_y_percent = off_y / camera_get_view_height(view_camera[0])
      
        var gui_x = off_x_percent * display_get_gui_width()
        var gui_y = off_y_percent * display_get_gui_height()
Thanks man! I was having some troubles too with drawing on the correct position of the GUI. This worked and it is awesome.
I've been at it for days without success... Thank you so much man.
 
Top