@Hudsonius erm, well, we're straying outside the question of drawing text inside a box and into some other game things, but let's see...
1) With regards to the quality of the font, that's really rather dependent upon the font, rather than GameMaker. It sounds as though you've got some really small text? Or have I got that wrong? Basically, some fonts are designed to be readable at small sizes, and some are not. GameMaker just draws whatever the font looks like, at the size you specify.
Two things to try:
a) If you need a small font, try searching up some so-called "tiny" fonts to use
https://www.dafont.com/tiny.font
b) If your fonts look blurry in GameMaker, and you're using tiny pixel fonts already, try turning
off the aliasing setting in the font resource box. (Or turn it down to a lower number). Aliasing is a technique for smoothing the edges of things by blurring them a bit, which is usually great for fonts--it removes rough, jaggy edges--but terrible if you want small fonts where every pixel must be precisely drawn,
2) Oki. Break it into tasks.
a) When you press Enter, you want the dialog to appear, right? So change the
mouse left pressed event into a
keyboard press Enter event.
b) You only want this to happen if the
Person object is "able" to speak--in other words, when the player character is near them. So, you need to set up the concept of "not able to speak" and then the conditions for "becoming able to speak"
c) You want speaking to go away when the player is more than 10 px away, so the
dialog box object needs to know which
Person object it is connected to.
In your
create event for the person, just put something like...
ableToSpeak = 0;
Then, in your step event for the
Person, put something like:
Code:
if( point_distance(x, y, PlayerCharacterObject.x, PlayerCharacterObject.y) <10 ){
ableToSpeak = 1;
}else{
speaking = 0;
}
(Replace
PlayerCharacterObject with whatever your player character's object name is)
Is it clear what that does?
The
Person object checks, every game step, to see whether or not the distance between its own x,y coordinates and the player character coordinates are less than 10. If so, then ableToSpeak is 1. In all other cases, ableToSpeak is zero.
Now, hook it up to the code that makes the dialog box object.
Remember, only make the dialog box if this Person Object is "ableToSpeak" and tell the dialog object which Person Object controls its destiny.
Event key pressed Enter
Code:
if( ableToSpeak==1 ){
nnn = instance_create_depth(x, y, -100, obj_dialog);
nnn.text = "Hello there, this is text that I am saying to you";
nnn.whoMadeMe = id;
}
So, the working dialog box will
only appear if ableToSpeak == 1, and we know that ableToSpeak will only equal 1 when the player character touches the
Person object.
Notice that I also added a value called whoMadeMe. This lets the dialog box know the ID of the
Person object that created it.
This is important because you wanted the dialog box to go away when the player moves more than 10 px away from the
Person object that created the text box.
Let me add one more thing to that, too:
Code:
if( ableToSpeak==1 and !instance_exists(obj_dialog) ){
nnn = instance_create_depth(x, y, -100, obj_dialog);
nnn.text = "Hello there, this is text that I am saying to you";
nnn.whoMadeMe = id;
}
In programming, the ! means "not". So, in plain English:
"If ableToSpeak is equal to one and there's
not already an instance of a dialog box on the screen....make one"
That'll keep you from getting multiple copies of the box (if the player presses Enter repeatedly).
c) So at this point, you have:
- A Person object that regularly updates "ableToSpeak" based on how close the player is to the Person.
- A key press event that creates a dialog box IF the Person is ableToSpeak at that moment and IF there's not already dialog on the screen.
- A dialog box object that knows who made it, and that draws a nice box with text.
Only thing missing is the part that makes the dialog box go away. Easy.
ADD THIS TO Create event for obj_dialog:
(Initially, a box doesn't know its maker. "noone" is a built-in GameMaker value for that concept).
Step event for obj_dialog:
Code:
if( !instance_exists(whoMadeMe) or whoMadeMe.ableToSpeak == 0 ){
instance_destroy();
}
The code above checks whether the "whoMadeMe"
Person still exists, and whether they are still "ableToSpeak."
So, when the player moves away, ableToSpeak becomes zero, and thus, the dialog box destroys itself.