• 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 [SOLVED] Menu Draw 's offset between first two items

Gamebot

Member
The problem I'm having is that there is an uneven space in between the first two items within my menu. I just created a generic one to see how it would draw. I tried drawing to the aspect ratio in width and height, x 16 and x 9. I even went as far as changing the font size to an aspect size. Same results always closer then the rest. See here:

screen shot.png

I have a new computer perhaps it's because of an aspect ratio issue. Normally it's a 1600 x 900 at 16:9. However my Windows display, cameras/views, and aspect ratio are all calculated. My room is 3000 x 3000 and as shown my windows display 1280 x 720 matches my cameras and views display at 1280 x 720.

MACROS SCRIPT:
Code:
#macro diswid display_get_width()
#macro dishei display_get_height()
#macro aspect scr_aspect()

SCR_ASPECT
Code:
/*
About this script:

Aspect ratio is how many pixels in width per pixels in height.
A 16:9 ratio means for every 16 pixels in width that are drawn
there will always be 9 pixels in height drawn.

Due to rounding errors we change to a string and format places using the string_format function.
First we get our aspect ratio: diswid/dihei = "1.78"
Then loop and divide to find which two numbers = "1.78"
Those two numbers is our aspect ratio.
*/

var asp, i, j, temp, out;

asp = string_format(diswid/dishei, 1, 2);
temp = 0;
out = "";

for ( i = 1; i < 25; i++) {
for ( j = 1; j < 25; j++) {
  temp = string_format(j/i, 1, 2);

  if (temp = asp) {
  out = string(j) + ":" + string(i)
  }

}
}

return out;

obj_menu
Create:
Code:
[ "Menu", "Edit", "Find", "Exit" ];
arrlen = array_length_1d(menu);
Draw:
Code:
draw_set_font(fnt_menu);

for ( i = 0; i < arrlen; i++) {
var entry = menu[i];
  draw_text(x + (i * 64), y, entry);
}

obj_camera
Create:
Code:
// Set window size and functions
window_set_fullscreen(false);
window_set_size(diswid, dishei);
window_set_caption("Awesome Game");

// Center window. Needs one step after window set functions
alarm[0] = 1;

// Resize drawing surface to our screen size
surface_resize(application_surface, diswid, dishei);
Alarm[0]:
Code:
window_center();
End Step:
Code:
camera_set_view_size(view_camera[0], diswid, dishei);
Room Start:
Code:
view_enabled = true;
view_visible[0] = true;
Draw:
Code:
draw_text(32, 32, "RES: " + string( diswid ) + " x " + string ( dishei ))
draw_text(32, 64, "ASP: " + string( aspect) );
Any insight is appreciated. Thanks.
 

jo-thijs

Member
The problem I'm having is that there is an uneven space in between the first two items within my menu. I just created a generic one to see how it would draw. I tried drawing to the aspect ratio in width and height, x 16 and x 9. I even went as far as changing the font size to an aspect size. Same results always closer then the rest. See here:

View attachment 32453

I have a new computer perhaps it's because of an aspect ratio issue. Normally it's a 1600 x 900 at 16:9. However my Windows display, cameras/views, and aspect ratio are all calculated. My room is 3000 x 3000 and as shown my windows display 1280 x 720 matches my cameras and views display at 1280 x 720.

MACROS SCRIPT:
Code:
#macro diswid display_get_width()
#macro dishei display_get_height()
#macro aspect scr_aspect()

SCR_ASPECT
Code:
/*
About this script:

Aspect ratio is how many pixels in width per pixels in height.
A 16:9 ratio means for every 16 pixels in width that are drawn
there will always be 9 pixels in height drawn.

Due to rounding errors we change to a string and format places using the string_format function.
First we get our aspect ratio: diswid/dihei = "1.78"
Then loop and divide to find which two numbers = "1.78"
Those two numbers is our aspect ratio.
*/

var asp, i, j, temp, out;

asp = string_format(diswid/dishei, 1, 2);
temp = 0;
out = "";

for ( i = 1; i < 25; i++) {
for ( j = 1; j < 25; j++) {
  temp = string_format(j/i, 1, 2);

  if (temp = asp) {
  out = string(j) + ":" + string(i)
  }

}
}

return out;

obj_menu
Create:
Code:
[ "Menu", "Edit", "Find", "Exit" ];
arrlen = array_length_1d(menu);
Draw:
Code:
draw_set_font(fnt_menu);

for ( i = 0; i < arrlen; i++) {
var entry = menu[i];
  draw_text(x + (i * 64), y, entry);
}

obj_camera
Create:
Code:
// Set window size and functions
window_set_fullscreen(false);
window_set_size(diswid, dishei);
window_set_caption("Awesome Game");

// Center window. Needs one step after window set functions
alarm[0] = 1;

// Resize drawing surface to our screen size
surface_resize(application_surface, diswid, dishei);
Alarm[0]:
Code:
window_center();
End Step:
Code:
camera_set_view_size(view_camera[0], diswid, dishei);
Room Start:
Code:
view_enabled = true;
view_visible[0] = true;
Draw:
Code:
draw_text(32, 32, "RES: " + string( diswid ) + " x " + string ( dishei ))
draw_text(32, 64, "ASP: " + string( aspect) );
Any insight is appreciated. Thanks.
Do you mean the issue is the difference in space between the words "Menu" and "Edit" and the words "Edit" and "Find"?
That space is due to you not using a monospaced font.
Menu contains pretty wide characters, whereas Edit contains "i" and "t", which are not wide at all.
 

TailBit

Member
Maybe use string_width like so:
GML:
draw_set_font(fnt_menu);

var i,w=0;
for ( i = 0; i < arrlen; i++) {
var entry = menu[i];
  draw_text(x + w, y, entry);
  w += string_width(menu[i]) + 32;
}
otherwise .. monospace font as mentioned
 

Gamebot

Member
Yep that would be it needed a mono spaced font. I feel dumb. I should have known it was something like that. I just decided to go with a control object.

Thanks.
 
Top