GameMaker: Studio

GameMaker: Studio

View Stats:
seblecaribou Feb 12, 2017 @ 8:11am
Text box
Hi everybody!

I'm working on a point and click type game, except I like it better when you go near the object to interact with them. Now I already have a couple of stuff put in the room, with accessible hitboxes. But I'm still wondering how to make a good looking text box, or just text.

At first, just to try it out (this my first time trying to make a videogame), I used this:

if keyboard_check_pressed(ord("E")) = true && distance_to_object(obj_tableau_hat) < 30
{
Show_message("A photo of a lady in a hat. Her smile reminds me of an old friend")
}

It works fine, but the windows' text box is horrible of course. So I wanted to know if there was a way, either by making each text an object that would pop, or by creating a specific font, to have something like this: http://imgur.com/XqTEhn6

With the text centered always at the same place and with the same font everytime, and keeping in mind that I want to interact with "E" (and quitting the text with "space" maybe). Any idea anyone?
Last edited by seblecaribou; Feb 13, 2017 @ 4:39am
< >
Showing 1-8 of 8 comments
seblecaribou Feb 13, 2017 @ 5:36am 
I looked up something like four or five tutorials on that particular stuff, and I can't find a way make it work easily. Right now, I'm trying the exact same script but replacing

Show_message("A photo of a lady in a hat. Her smile reminds me of an old friend");

by

draw_text(40,50,"A photo of a lady in a hat. Her smile reminds me of an old friend...");

and that doen't work at all. Please, any input?
This drove me crazy all weekend é_è
Last edited by seblecaribou; Feb 13, 2017 @ 6:51am
seblecaribou Feb 13, 2017 @ 6:54am 
This is seriously driving me insane. I just don't get why it is so complicated to just have a message display when you're close to an object. All I want is to keep the fact that I press a button near the object and it displays a text in the proper size and font, and the text disappears when I press the button again. No effect, just the text ;_;

All I can find is tutorial on how to make a text box, jrpg style, with typewriter effect and the possibility to speed up the text and all...I just don't know what I am supposed to leave out of these codes if I just want the text to display.
Last edited by seblecaribou; Feb 13, 2017 @ 1:27pm
Diveyoc Feb 13, 2017 @ 8:28am 
Do you know how to create fonts? It sounds like you need to create a new font to your liking. In the tree branch along with sprites and objects and such, there is a folder called "fonts". Right click on it and select "Create Font"
Pick the font that you want and give it name, just like you name anything else. Lets call it font_text_log. Try a size of 12 to start. You can also try Arial Rounded MT Bold as an example. Now that you have created a font, you can use it in your code as shown below.
Also, I think you probably want to use the draw_text_ext command so that you can control the length of your text line and the spacing between lines. Also set the color.

draw_set_color(c_white);
draw_set_font(font_text_log);
draw_text_ext(40, 50, "A photo of a lady in a hat. Her smile reminds me of an old friend", 18, 200);
Diveyoc Feb 13, 2017 @ 8:44am 
As for your key press. You can use a variable to toggle the text on and off with something like this in your player object:

Create Event:
text_index = 0;

Step Event:
if keyboard_check_pressed(ord('T'))
text_index += 1;
if text_index > 1
text_index = 0;

Draw or Draw GUI Event:
draw_set_color(c_white);
draw_set_font(font_text_log);
if text_index != 0
&& point_distance(x, y, your_object.x, your_object.y) < 200
draw_text_ext(40, 50, "A photo of a lady in a hat. Her smile reminds me of an old friend", 18, 200);

Make sure you review the code and understand how and why it works.
Diveyoc Feb 13, 2017 @ 8:56am 
If you want to experiment with a crude background text box, add this rectangle command and mess with the parameters to fit your text.

Draw or Draw GUI Event:
draw_set_color(c_black);
draw_set_alpha (0.7);
draw_roundrect(35,45,215,85,0);
draw_set_alpha (1);
draw_set_color(c_white);
draw_set_font(font_text_log);
if text_index != 0
&& point_distance(x, y, your_object.x, your_object.y) < 200
draw_text_ext(40, 50, "A photo of a lady in a hat. Her smile reminds me of an old friend", 18, 200);

Just remember in draw events, everything draws in sequence. So with the code above, it draws the rectangle FIRST. And then it draws the text on top of the rectangle.
If you put the draw text code first, then the rectangle would get drawn over the top of the text.

Edit:
Also notice how I changed the alpha here. Everytime you draw something, if you want a different alpha, font, or color, you need to set it each time. Unless you are using the same settings for all text or drawing, in which case you can just set it one time at the top of your draw event.
So, in this example I set the alpha transparency of the rectangle to 0.7. But then I change the alpha back to 1 so that I have full color alpha when drawing the text after drawing the rectangle.
Last edited by Diveyoc; Feb 13, 2017 @ 9:01am
Diveyoc Feb 13, 2017 @ 9:06am 
You can also draw your own sprite for a text box and use draw_sprite instead of draw_rectangle as shown here.
http://steamcommunity.com/sharedfiles/filedetails/?id=863401756
seblecaribou Feb 13, 2017 @ 1:02pm 
Thans so much for the answer. I'll try that tonight!
seblecaribou Feb 13, 2017 @ 2:44pm 
Okay I'm in GMS.

For example the:

draw_set_color(c_white);
draw_set_font(font_text_log);
draw_text_ext(40, 50, "A photo of a lady in a hat. Her smile reminds me of an old friend", 18, 200);

That, I get. It's telling GMS that under a certain circumstance, it will draw a text, in white, with the fon_text_log and at the coordonates, and the text written in " ". I don't know what the 18,200 stands for though; I'm going to assume it is for the number of characters and/or the distance between two lines of text one over the other. But simple question: where do I type the code? Is it a script? Do I put it inside the "step" event for the main character?

As for the rest, I don't really understand how to put it in practice even though I finally understood the underlying logic behind the process, but I'm going to say this: I'm a real beginner, and I don't now how to manipulate this software yet.

So I keep this code under my pillow, and I'm going to watch every single rpg tutorial from Heartbeast on YT, which hopefully will give me the basics to understand your answer, because I obviously lack the very fundations to make it.

Thank you nonetheless! That will come in handy at some point. :D
< >
Showing 1-8 of 8 comments
Per page: 1530 50

Date Posted: Feb 12, 2017 @ 8:11am
Posts: 8