r/gamemaker • u/Powerful-Dragonfly32 • 1d ago
Help! Trigger Multiple Text Boxes based on Player's X-Coordinates in a Single Room
Hi everyone.
I'm new to Gamemaker and more complicated coding like this (have some CSS and HTML experience from years back). I've been working with tutorials on Youtube (mostly Peyton Burnham & Friendly Cosmonaut), which cover a lot, but I'm struggling to get the above topic to work and I'm not finding a ton of useful help online. It seems like it should be simple enough, but my child mind apparently needs step-by-step instructions. Anyone got a solution for this?
I'm using Burnham's tetbox tutorial as a base.
Here is the code for my obj_textbox object.
CREATE:
global.in_dialogue = true;
depth = -9999;
//---------THE TEXT---------//
page = 0;
page_number = 0;
text[0] = "I'm so glad you're back!"
text[1] = "I've been waiting for you."
text[2] = "I've missed you very much..."
text_length[0] = string_length(text[0]);
draw_char = 0;
text_spd = 1;
setup = false;
DRAW:
accept_key = keyboard_check_pressed(vk_space) or mouse_check_button_pressed(mb_left);
textbox_x = camera_get_view_x( view_camera[0] )+ 10;
textbox_y = camera_get_view_y( view_camera[0] ) + 250;
//---------SETUP---------//
if setup == false
{
setup = true;
draw_set_font(global.font_main);
draw_set_valign(fa_top);
draw_set_halign(fa_left);
//--------LOOP THRU PAGES---------//
page_number = array_length(text);
for(var p = 0; p < page_number; p++)
{
//---------Find how many characters on each page and store that # in the "text_length" array---------//
text_length[p] = string_length(text[p]);
//---------Get the x position for the textbox---------//
//--------No Character (center textbox on screen)---------//
text_x_offset[p] = 44;
}
}
//---------TYPING TEXT---------//
if draw_char < text_length [page]
{
draw_char += text_spd;
draw_char = clamp(draw_char, 0, text_length[page]);
}
//--------FLIP THRU PAGES----------//
if accept_key
{
//----------IF TYPING IS DONE---------//
if draw_char == text_length[page]
{
//---------NEXT PAGE---------//
if page < page_number-1
{
page++;
draw_char = 0;
}
//--------DESTROY TEXTBOX---------//
else
{
instance_destroy();
}
}
//---------IF TYPING NOT DONE---------//
else
{
draw_char = text_length[page];
}
}
//---------TEXTBOX PARAMETERS---------//
textbox_width = 200;
textbox_height = 64;
border = 8;
line_sep = 12;
line_width = textbox_width - border*2;
textb_spr = spr_textbox;
textb_img = 0;
textb_img_spd = 1/60;
//--------DRAW TEXTBOX---------//
textb_img += textb_img_spd;
textb_spr_w = ( sprite_get_width(textb_spr) / 2 )
textb_spr_h = ( sprite_get_height(textb_spr) / 2 );
//---------BACK OF TEXTBOX---------//
draw_sprite_ext(textb_spr, textb_img, textbox_x + text_x_offset[page], textbox_y, textbox_width/textb_spr_w, textbox_height/textb_spr_h, 0, c_white, 1);
//---------DRAW TEXT---------//
var _drawtext = string_copy(text[page], 1, draw_char);
draw_text_ext(textbox_x + text_x_offset[page] + border + 5, textbox_y + border +
DESTROY:
global.in_dialogue = false;
if (text_length[0])
{
instance_destroy();
}
1
u/RykinPoe 1d ago
Please share you code.
What you are trying to do should be simple. Just need to reference obj_player.x in your textbox drawing code. May need to run that through a function to convert room coordinates to camera or GUI coordinates if you are drawing the textbox to the GUI layer. I have no idea how Peyton did it in their tutorial.