Help With Textboxes

J

Jestermask

Guest
So I almost did it, but not quite...
When Object_Player collides with oCharacter the text in the textbox is "stretched" like in the first pictue: http://imgur.com/a/OC93i ...Although it's as it should be every other time the player collides with the character again, the 1st time is always wrong... Probably some dumb mistake like always, but I can't figure it out this time... I would appreciate any help! :)

Here's the code:
oTextbox

CREATE
text = "object text"

boxwidth = sprite_get_width(textbox);
stringheight = string_height(text);

DRAW
//draw textbox
draw_sprite(textbox, 0, x - sprite_get_width(textbox)/2, y)

//draw text
draw_set_font(Gothic_Font)
draw_text_ext(x - sprite_get_width(textbox)/2, y, text, stringheight, boxwidth)


oCharacter

CREATE
mytext = "Hello!"
mytextbox = noone

STEP
if (place_meeting(x, y, Object_Player))
{
if (mytextbox == noone)
{
mytextbox = instance_create_layer(x, y, "text_layer", Object_Textbox);
mytextbox.text = mytext;
}
} else{
if (mytextbox != noone)
{
instance_destroy(mytextbox);
mytextbox = noone;
}
}
 

Simon Gust

Member
I'm guessing that stringheight = string_height(text) won't adapt to the new string set in
Code:
if (mytextbox == noone)
{
 mytextbox = instance_create_layer(x, y, "text_layer", Object_Textbox);
 mytextbox.text = mytext;
}
Create events always run before setting variables externally.
So stringheight will still be the height of "object text".

I suggest updating the string height in here again.
Code:
if (mytextbox == noone)
{
 mytextbox = instance_create_layer(x, y, "text_layer", Object_Textbox);
 mytextbox.text = mytext;
 mytextbox.stringheight = string_height(mytextbox.text);
}
 
J

Jestermask

Guest
Hmmm, I understand your suggestion, but it didn't change anything...
 
Top