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

How to add audio sounds to textbox dialogues?

W

Wafi Hussain

Guest
I am using this framework given in this video,

to make the NPC object produce audio sounds for textbox dialogues. So I would like to know how to add voice overs to a specific dialogue. Here is the code,

obj_NPC
Create Event:
msg = [
["Hey there!", "Rob", sImage1],
["Hello! It's-a-me, player!", "Player", sImage0],
["Player, that's a weird name.", "Rob", sImage1],
["Well, anyway. Do you wanna earn some money? I've got quite the job for you!", "Rob", -1],
["no", "Player", sImage0]
]

Left Pressed
if (!instance_exists(oTextbox)) {
// Create
var _tb = instance_create_layer(0, 0, "Instances", oTextbox);

// Add messages to textbox's list
var _list = _tb.messages;

for (var i=0; i<array_length_1d(msg); i++) {
var _arr = msg;

ds_list_add(_list, _arr);
}
}

obj_Textbox

Create Event:
// Messages
messages = ds_list_create();
messageID = 0;

// Current message
messageText = "";
messageChar = 0;
messageSpeed = 0.3;

// Message properties
enum MSG {
TEXT,
NAME,
IMAGE
}

// GUI dimensions
var _guiW = display_get_gui_width();
var _guiH = display_get_gui_height();

// Textbox dimensions
height = floor(_guiH * 0.45);
width = _guiW;

// Position on screen
x = 0;
y = _guiH - height;

// Other properties
padding = 8;

Clean Up:
ds_list_destroy(messages);

Step:
var _arr = messages[| messageID];

var _text = _arr[MSG.TEXT];

// Get message string
messageText = string_copy(_text, 1, messageChar);

// String not fully drawn
if (messageChar <= string_length(_text)) messageChar += messageSpeed;

// String fully drawn
else if (keyboard_check_pressed(vk_enter)) {
// Go to next message
if (messageID < ds_list_size(messages) - 1) {
messageID++;
messageChar = 0;
}
// Close textbox
else {
instance_destroy();
}
}

Draw GUI:
var _arr = messages[| messageID];

var _name = _arr[MSG.NAME];
var _image = _arr[MSG.IMAGE];

// Set text font
draw_set_font(font0);

// Draw textbox
draw_9slice(x, y, width, height, sTextbox, 0);

// Draw position
var _drawX = x + padding;
var _drawY = y + padding;

// Draw image
if (sprite_exists(_image)) {
var _imageW = sprite_get_width(_image);
var _imageH = sprite_get_height(_image);

// Draw
draw_sprite(_image, 0, _drawX + _imageW / 2, _drawY + _imageH / 2);

// Offset drawing position for text
_drawX += _imageW + padding;
}

// Text color
draw_set_color(c_black);

// Draw name
draw_text(_drawX, _drawY, _name);

_drawY += string_height(_name) + padding;

// Get maximum width for text
var _maxW = width - (_drawX + padding);

// Draw text
draw_text_ext(_drawX, _drawY, messageText, -1, _maxW);

// Reset
draw_set_color(c_white)

Hope there is a way to do that.
 

obscene

Member
You probably figured it out by now but you want to playba sound at the same time you run the line messageChar += messageSpeed. Check if messageChar equals itself floored.
 
Top