Page 1 of 2
Typo - Typewriter lib
Posted: Sat Aug 09, 2014 9:59 pm
by Eamonn
Typo is a simple library that allows you to effortlessly add a typewriter effect to your game. All you need to do it pass it in the text, delay, width to wrap, alignment, x position, y position and the font!
I made a tutorial on how to create this effect, and I will add a link here and remove this text once it is uploaded. It shows the basic principles of how to create such an effect without this library if you wish to do so.
Source code and download can be found on GitHub:
https://github.com/sonic2kk/Typo
Please suggest any changes or additions I could make!
Have a great day, and thanks for checking this out!
Changelog:
1.1
Added colours
1.0
Original Release
Re: Typo - Typewriter lib
Posted: Sun Aug 10, 2014 7:12 am
by Rukiri
This is pretty neat, I could easily see this be updated for RPG Dialogs. Only thing missing is special characters for coloring text.
Re: Typo - Typewriter lib
Posted: Sun Aug 10, 2014 2:11 pm
by Eamonn
Rukiri wrote:This is pretty neat, I could easily see this be updated for RPG Dialogs. Only thing missing is special characters for coloring text.
Colours: Got it! Adding it now!
Special Characters: Not sure what you mean. It should support special characters such as Ö,Ø, etc already. If you could clarify I'd be more than happy to help
EDIT: Colours have been added!
Still not sure what you mean by Special Characters
Re: Typo - Typewriter lib
Posted: Sun Aug 10, 2014 2:32 pm
by davisdude
I think what they mean is like how you use the
tags on the forums, to set certain parts a color.
Re: Typo - Typewriter lib
Posted: Sun Aug 10, 2014 2:43 pm
by Eamonn
davisdude wrote:I think what they mean is like how you use the
tags on the forums, to set certain parts a color.
Ohh... Hm, I'll look into how to do this. I'll add it along with support for special characters, which I know know is a problem and isn't so easy to tackle. I'm using string.byte and string.char to hopefully help
Thanks to telling me this though. I guess for the color tags I'd just need to add a parser of some sort, right?
Re: Typo - Typewriter lib
Posted: Sun Aug 10, 2014 3:10 pm
by davisdude
Definitely. I took something like this on about last year, and you can feel free to
take a look at it. Or Robin's
library. To be honest, I based the first styling of mine off of Robin's.
Re: Typo - Typewriter lib
Posted: Mon Aug 11, 2014 5:52 am
by Sam Storms
Very nice, I'm starting on a platformer, I'm gonna use typo on it
Re: Typo - Typewriter lib
Posted: Mon Aug 11, 2014 5:57 pm
by Eamonn
Sam Storms wrote:Very nice, I'm starting on a platformer, I'm gonna use typo on it
Awesome! Glad to see it's useful. I hope to add more to it eventually (such as being able to get certain properties)
Trying to figure out how to do the string parsing, but I'll get there. I want to write it myself, so that typo has 0 external dependencies (except for Lua and LÖVE, of course
). Then you can add some more colorful things to your text.
Re: Typo - Typewriter lib
Posted: Mon Aug 11, 2014 6:48 pm
by Sam Storms
Eamonn wrote:
Awesome! Glad to see it's useful. I hope to add more to it eventually (such as being able to get certain properties)
Trying to figure out how to do the string parsing, but I'll get there. I want to write it myself, so that typo has 0 external dependencies (except for Lua and LÖVE, of course
). Then you can add some more colorful things to your text.
I'm looking forward to it
If I ever get to your level of understanding, I'll help with whatever you need help with
Re: Typo - Typewriter lib
Posted: Tue Aug 12, 2014 5:25 pm
by Rukiri
Eamonn wrote:Sam Storms wrote:Very nice, I'm starting on a platformer, I'm gonna use typo on it
Awesome! Glad to see it's useful. I hope to add more to it eventually (such as being able to get certain properties)
Trying to figure out how to do the string parsing, but I'll get there. I want to write it myself, so that typo has 0 external dependencies (except for Lua and LÖVE, of course
). Then you can add some more colorful things to your text.
I don't know how much this would help you, but this is my old code for a textbox dialogue system for game maker that I wrote quite awhile ago.
Create Event:
Code: Select all
textbox_surface = surface_create(256,224);
surface_set_target(textbox_surface);
draw_clear_alpha(0,0);
surface_reset_target();
text_entire = line_break_support(global.textbox_text);
text_letter = "";
draw_x = 0;
draw_y = 0;
current_position = 1;
max_position = string_length(text_entire) + 1;
color_1 = c_white;
color_2 = c_white;
global.cur_pos = current_position;
global.max_pos = max_position;
keyboard_clear(vk_space);
Step:
Code: Select all
if(current_position <= max_position) {
if(draw_y <= 30) {
text_letter = string_copy(text_entire,current_position,1);
switch(text_letter) {
case "]":
color_1 = c_aqua;
color_2 = c_blue;
break;
case "^":
color_1 = c_red;
color_2 = c_dkred;
break;
case "~":
color_1 = c_lime;
color_2 = c_green;
break;
case "`":
color_1 = c_white;
color_2 = c_white;
break;
case "#":
draw_x = 0;
draw_y += 15;
break;
default:
surface_set_target(textbox_surface);
draw_set_font(global.textbox_letters);
draw_text_color(view_xport+draw_x+28,view_yport+draw_y+161,text_letter,color_1,color_1,color_2,color_2,1);
surface_reset_target();
draw_x += string_width(text_letter);
draw_set_font(-1);
if(draw_x >= 195) {
draw_x = 0;
draw_y += 15;
}
}
current_position += 1;
}
}
// setup continue cursor
if(current_position >= max_position) {
current_position = max_position;
draw_x = 0;
draw_y = 0;
if (keyboard_check(vk_space)) {
instance_destroy();
}
}
Draw:
Code: Select all
draw_surface(textbox_surface,view_xview[0],view_yview[0]);
draw_set_font(global.textbox_letters);
draw_set_color(c_ltgray);
if(current_position >= max_position) {
draw_sprite(spr_block,-1,view_xport+draw_x+113,view_yport+draw_y+175);
}
draw_text(x,y,draw_x);
Destroy:
Code: Select all
draw_surface(textbox_surface,view_xview[0],view_yview[0]);
draw_set_font(global.textbox_letters);
draw_set_color(c_ltgray);
if(current_position >= max_position) {
draw_sprite(spr_block,-1,view_xport+draw_x+113,view_yport+draw_y+175);
}
draw_text(x,y,draw_x);
Keyboard Press Space:
Code: Select all
if(draw_y >= 45) {
instance_destroy();
textbox(string_copy(text_entire,current_position,string_length(text_entire)-current_position+1),color_1,color_2);
}
Demo Object:
Create:
Code: Select all
global.textbox_letters = font_add_sprite(spr_letters,ord('!'),1,1);
global.textbox_text = "";
Press Enter:
Code: Select all
textbox("Testing a very long text message, maybe the pointer will get a ~hint?");