Methudek
Member
I want to create new obj_textbox and I doesn't know to switch beetwen
my speakblock:
and this is my obj_textbox:
obj_textbox_1
and obj_textbox_2
my speakblock:
CREATE
GML:
text_id = "";
STEP
Code:
var _s = id;
if position_meeting(mouse_x, mouse_y, id) && mouse_check_button_pressed(mb_left)
{
create_textbox(text_id);
}
and this is my obj_textbox:
CREATE
Code:
depth = -9999;
//textbox parameters
textbox_width = 300;
textbox_height = 29;
border = 9;
line_sep = 12;
line_width = textbox_width - border*2;
txtb_spr = spr_textbox;
txtb_img= 0
txtb_img_spd = 2/20;
//the text
page = 0;
page_number = 0;
text[0] = "";
text_length[0] = string_length(text[0]);
draw_char = 0;
text_spd = 1
//options
option[0] = "";
option_link_id[0] = -1;
option_pos = 0;
option_number = 0;
setup = false;
DRAW
Code:
accept_key = keyboard_check_pressed(vk_space);
textbox_x = camera_get_view_x( view_camera[1] );
textbox_y = camera_get_view_y( view_camera[0] ) + 167;
//--------------------------------setup--------------------------//
if setup == false
{
setup = true;
draw_set_font(global.font_main);
draw_set_valign(fa_top);
draw_set_halign(fa_left);
//loop through pages
for(var p = 0; p < page_number; p++)
{
//find how many characters are on each page and store that number in ther "text_length" array
text_length[p] = string_length(text[p]);
//get the x position for the textbox
//no characters ( center the textbox )
text_x_offset[p] = 10;
}
}
//-------------------typing the text----------------------------//
if draw_char < text_length[page]
{
draw_char += text_spd;
draw_char = clamp(draw_char, 0, text_length[page]);
}
//------------------flip through 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
{
//link text for options
if option_number > 0 {
create_textbox(option_link_id[option_pos])
}
instance_destroy();
}
}
//if not done typing
else
{
draw_char = text_length[page];
}
}
//----------------draw the textbox----------------------------//
var _txtb_x = textbox_x + text_x_offset[page];
var _txtb_y = textbox_y;
txtb_img += txtb_img_spd;
txtb_spr_w = sprite_get_width(txtb_spr);
txtb_spr_h = sprite_get_height(txtb_spr);
//back of the textbox
draw_sprite_ext(txtb_spr, txtb_img, textbox_x + text_x_offset[page], textbox_y, textbox_width/txtb_spr_w, textbox_height/txtb_spr_h, 0, c_white, 1);
//------------------options------------------------------------//
if draw_char == text_length[page] && page == page_number - 1
{
//option selection
option_pos += keyboard_check_pressed(vk_down) - keyboard_check_pressed(vk_up);
option_pos = clamp(option_pos, 0, option_number-1);
//draw the options
var _op_space = 15;
var _op_bord = 4;
for (var op = 0; op < option_number; op++)
{
//the option box
var _o_w = string_width(option[op]) + _op_bord*2;
draw_sprite_ext(txtb_spr, txtb_img, _txtb_x + 16, _txtb_y - _op_space*option_number + _op_space*op, _o_w/txtb_spr_w, (_op_space-1)/txtb_spr_h, 0, c_white, 1)
//the arrow
if option_pos == op
{
draw_sprite(spr_arrow, 0, _txtb_x, _txtb_y - _op_space*option_number + _op_space*op)
}
//the option text
draw_text(_txtb_x + 16 + _op_bord, _txtb_y - _op_space*option_number + _op_space*op + 2, option[op]);
}
}
//draw the text
var _drawtext = string_copy(text[page], 1, draw_char);
draw_text_ext(textbox_x + text_x_offset[page] + border, textbox_y + border, _drawtext, line_sep, line_width)