我已经为你翻译好了:
我到了建立基本的创建、步骤和绘制GUI事件以及"创建对话"脚本的地方。现在是时候在游戏中写一个测试的对话框了,然而完全没有显示出来!
我的Create事件在obj_dialog:
messages = [];
current_message = -1;
current_char = 0;
draw_message = " ";
char_speed = 0.5;
input_key = mb_left;
gui_w = display_get_gui_width();
gui_h = display_get_gui_height();
我的Step事件在obj_dialog:
if (array_length(messages) == 0) exit;
if (current_message < 0) current_message = 0;
//get message from array
var _str = messages[current_message].msg;
//checking if the message has not been fully drawn yet
if (current_char < string_length(_str))
{
//you can press input key to make the current text go twice as fast
current_char += char_speed * (1 + keyboard_check(input_key))
draw_message = string_copy(_str, 0, current_char)
}
//else if the string has finished being drawn completely
else if (keyboard_check_pressed((input_key)))
{
current_message++;
if (current_message >= array_length(messages))
{
instance_destroy()
}
else
{
current_char = 0;
}
}
我的Draw GUI事件在obj_dialog:
gui_w = display_get_gui_width();
gui_h = display_get_gui_height();
//draw width, draw height, textbox width, textbox height
var _dx = 0
var _dy = gui_h * 0.7;
var _boxw = gui_w
var _boxh = gui_h - _dy;
draw_sprite_stretched(spr_box, 0, _dx, _dy, _boxw, _boxh);
_dx += 16
_dy += 16
draw_set_font(Font1);
var _name = messages[current_message].name;
draw_text(_dx, _dy, _name);
//draw message 40 px below name
_dy += 40
//wraps text around if it goes past line,
//so that it stays inside box.
draw_text_ext( _dx, _dy, draw_message, -1, _boxw - _dx * 2)
以下是我的对话脚本:
///all of the diaglogue script
function create_dialog(_messages){
if (instance_exists(obj_dialog)) return;
var _inst = instance_create_depth(0, 0, 0, obj_dialog);
_inst.messages = _messages;
_inst.current_message = 0;
}
以下是我的测试场景,位于obj_player,Step事件:
//Player Step Event for test
if (keyboard_check_pressed(mb_left)) {
create_dialog([
{
name: "test",
msg: "yay, it works"
}
]);
}
我已经把自己搞得很乱了 +bananas,试图找出问题,但是我认为我遵循了教程的每一个字节 :( 没有显示任何错误信息,这也很不寻常,希望这意味着有一个非常简单的解决方案,这我完全没有察觉到 !
评论 (0)