• 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!

GML Need some help with signposts and text windows!

C

Consuming Octorocks

Guest
I'm super new to Gamemaker 2 but I've figured out enough to get by. OK so my view port is super zoomed to 480x270 pretty much all the time and I have made an signpost object. I set a variable called "message" to a string (what I want the sign to say) in the creation code of the sign in the room editor. What I WANT is to have the sign draw its message in text relative to the sign when the player touches it (the message goes away once the player is no longer colliding with the sign), HOWEVER since the viewport is zoomed in, the text it tries to draw is waaaayyyy too big. I've tried cranking the font size down in the font editor but at that point its unreadable. I did manage to still draw the message but I had to use the same object that controls the GUI, but it draws the message on a fixed point on the screen rather than relative to the actual signpost like I wanted.
Could someone help me find a way to draw the text box relative to the signpost in the room rather than using the GUI? GUI.gif
 
Option 1:
Go back to drawing the text in the room instead of the gui layer. But this time not with a true type font but with your own bitmap or sprite font. Creating a pixelartsy sprite font is really simple and its simple to set up your own sprite font. Just google for "Game Maker Studio sprite font" to see several tutorials.
You can use my sprite font if you want to but it might be too large for your resolution and its only capitals and no symbols like point or comma. Easy to add though:
bitmap-font.png
In a pixel art game I'd probably go for this option because I get full control on how the font looks. No smearing, no antialising, no weird stuff happening as with true types.

Option 2:
Stick to the gui layer. You'll need to calculate the textbox coordinates from the sign post coordinates in the room and the view offset and the difference in scale between the view and the gui layer.

To get the view offset you can use functions like:
camera_get_view_x(view_camera[0]);

To get the size of the view:
camera_get_view_width(view_camera[0]);

And to get the size of the gui:
display_get_gui_width();
 
C

Consuming Octorocks

Guest
So @The Reverend . I tried Option 1 and its not working for me. I tried your font and another and niether seem to work! Since you suggested it I would assume you know a fair bit about the subject so many helps would be much appreciate :(



globalvar bitmap_font;
bitmap_font = font_add_sprite_ext(spr_font_2," !\"#$%&'()*+,-./0123456789:'<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~",false,0);

draw_set_font(bitmap_font);
draw_text(x,y,"Look! I'm a Text Box!");


(I really didn't want to go into Option 2 since I'm ACTUALLY the worst at math)
 

Attachments

Just as a test using the font I posted:

  • Import the sprite, name it spr_bitmap_font.
  • Edit the sprite.
  • In the horizontal menu up top while editing a sprite you'll see a new menu option "Image" and in there the option "Convert to frames"
  • 40 frames, 10 per row, 16px by 16px

Create event:
Code:
global.fnt_bitmap_font = font_add_sprite_ext(spr_bitmap_font,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",true,1);
Note:
  • in the string I only entered the numbers and characters that are actually on the sprite and I set up the string in the exact same order as the frames of the sprite are.
  • Also I set proportional to true. set it to false if you want a mono-space font only.
  • And I set separation to 1 because with proportional enabled the letters wouldn't have a gap anymore.

Draw event:
Code:
draw_set_font(global.fnt_bitmap_font);
draw_text(x,y,"LOOK! I'M A TEXT Box!");
draw_set_font(-1);
Now if you run this you'll see most of the characters being drawn. However exclamation mark, hyphen and the lower characters are not written because they're not in the font sprite and font string. You'll need to add those if you want GMS to be able to draw them.

But as I said: creating a pixelarts font is really simple and can be done from within GMS sprite editor even - no fancy drawing software needed.

Edit:
You might need to add a space character as well. Don't remember.
 
Last edited:
C

Consuming Octorocks

Guest
@The Reverend This is embarassing. I just realized that any READABLE sprite font would be too big. How would I go about option 2? XD sorry
 
Option 2 is drawing on the gui layer.

  • Lets say the textbox should be anchored to the sign posts x|y in the room.
  • And lets assume the object drawing the text box is the sign post.
  • Set the gui layer to a higher resolution than your view. i.e. to the same size as your view port.
  • Use a Draw GUI event to draw the text box
  • The sign posts coordinate in the room can be converted to the gui layer coordinate like this (I hope I got the maths right there):

    x of where the signpost is in the room minus x of where the view currently is in the room times how much larger the gui is than the view.

    In Pseudo code:
    Code:
    x_on_gui = (x - view_x) * gui_width / view_width
    or with functions:
    Code:
    x_on_gui = (x - camera_get_view_x(view_camera[0])) * display_get_gui_width() / camera_get_view_width(view_camera[0]);
  • And the same with y and height
Now of course if display_get_gui_width() and camera_get_view_width(view_camera[0]) would never change, then you'd set up a scale factor in create event already:
Code:
gui_scale_factor = display_get_gui_width() / camera_get_view_width(view_camera[0]);
and then just use that factor in the draw gui event:
Code:
x_on_gui = (x - camera_get_view_x(view_camera[0])) * gui_scale_factor;
This means you can use any true type font if your gui is high res (apart from legal reasons). Just make sure it looks consistent with your game art still.
 
Top