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

[SOLVED] The first time a textbox is activated, the spacing is off.

A

AndHeDrew

Guest
Hello! I've been scratching my head about this, and would be very grateful for help!

I've been adding character textboxes to my game, and the first time I activate a textbox, the words are pushed farther down the box then they're supposed to be. (The X alignment is fine, it's the Y alignment that's off.)
This is just the first time I activate ANY textbox after starting the game, not EACH textbox. If I go back to the same character and talk to them again, it's fine. It only happens once each time I run the game, then everything is normal.

First time:

Screen Shot 2018-02-20 at 12.02.05 PM.png

Every time after:
Screen Shot 2018-02-20 at 12.02.17 PM.png

Here's what I've done:
---

Version: 2.1.3.273

Object: o_textbox

o_textbox: Create
Code:
text_ = "text"
page_ = 0;

xBuffer_ = 10;
yBuffer_ = 10;

boxHeight_ = sprite_get_height(s_textbox);
boxWidth_ = sprite_get_width(s_textbox);
stringHeight_ = string_height(text_);
creator = noone;
charCount_ = 0;
name_ = noone;
o_textbox: Step

Code:
if(keyboard_check_pressed(vk_space)) {
   if(charCount_ < string_length(text_[page_])) {
       charCount_ = string_length(text_[page_])   
   }
   
   else if(page_+1 < array_length_1d(text_)){
       page_ += 1;   
       charCount_ = 0;
   } else{
       instance_destroy();
       creator.alarm[1] = 1;
   }
}
o_textbox: draw
Code:
//draw textbox

draw_rectangle(x-2, y-2, x+boxWidth_+2, y+boxHeight_+2, false);
draw_sprite(s_textbox, 0, x, y);

//set font
draw_set_font(f_text);

//incriment character counter every frame
if (charCount_ < string_length(text_[page_])) {
   charCount_ += 1;
}

//copy part of the text
textPart_ = string_copy(text_[page_], 1, charCount_);

//Draw the name
draw_set_color(c_orange);
draw_set_halign(fa_center);
draw_text(x+boxWidth_/2, y+yBuffer_/2, name_);
draw_set_halign(fa_left);

//Draw Part of the Text
draw_set_color(c_white);
draw_text_ext(x+xBuffer_, y+stringHeight_+yBuffer_, textPart_, stringHeight_, boxWidth_ - (2*xBuffer_));
Object: o_parent_talker (the parent object for talking characters)

o_parent_talker: create
Code:
myTextbox_ = noone;
myName_ = "";

myText_[0] = "";
o_parent_talker: step
Code:
/// @description Insert description here
if(place_meeting(x,y, o_player)) {
   //if I haven't created my textbox, create one.
   if(keyboard_check_pressed(vk_space)){
       if(myTextbox_ == noone){
           myTextbox_ = instance_create_layer(x,y, "Text", o_textbox);
           myTextbox_.text_ = myText_;
           myTextbox_.creator = self;
           myTextbox_.name_ = myName_;
       }
   }
} else {
   if(myTextbox_ != noone){
   instance_destroy(myTextbox_);
   myTextbox_ = noone;
   }
}
o_parent_talker: alarm 1

Code:
myTextbox_ = noone;

Object: o_mother (the child object, a talking character)

o_mother: create

Code:
event_inherited();
myName_ = "Mom";

myText_[0] = "Hello, dear!";
myText_[1] = "I'm so proud of you. I'm sure you'll do your best today.";

Deeply grateful for any assistance!
 

Sergio

Member
Maybe the first time you instantiate a textbox, the font isn't set to your customized one, so when, in the create event, you calculate

stringHeight_ = string_height(text_);

it throws an undesired height, based on default font. Try to set the f_text font before.
 
A

AndHeDrew

Guest
Maybe the first time you instantiate a textbox, the font isn't set to your customized one, so when, in the create event, you calculate

stringHeight_ = string_height(text_);

it throws an undesired height, based on default font. Try to set the f_text font before.
That's done it! Thank you so much!!!

For anyone who needs it, I added draw_set_font(f_text); to the "o_textbox" object's create event:

o_textbox: create
Code:
text_ = "text"
page_ = 0;
draw_set_font(f_text);

xBuffer_ = 10;
yBuffer_ = 10;

boxHeight_ = sprite_get_height(s_textbox);
boxWidth_ = sprite_get_width(s_textbox);
stringHeight_ = string_height(text_);
creator = noone;
charCount_ = 0;
name_ = noone;
 
Top