Typo - Typewriter lib

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Eamonn
Party member
Posts: 550
Joined: Sat May 04, 2013 1:29 pm
Location: Ireland

Typo - Typewriter lib

Post 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! :D

Changelog:

1.1
Added colours

1.0
Original Release
Last edited by Eamonn on Sun Aug 10, 2014 3:01 pm, edited 2 times in total.
"In those quiet moments, you come into my mind" - Liam Reilly
User avatar
Rukiri
Citizen
Posts: 68
Joined: Mon Jun 27, 2011 5:52 am

Re: Typo - Typewriter lib

Post 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.
User avatar
Eamonn
Party member
Posts: 550
Joined: Sat May 04, 2013 1:29 pm
Location: Ireland

Re: Typo - Typewriter lib

Post 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 :D

EDIT: Colours have been added! :) Still not sure what you mean by Special Characters
"In those quiet moments, you come into my mind" - Liam Reilly
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: Typo - Typewriter lib

Post by davisdude »

I think what they mean is like how you use the

Code: Select all

[color][/color]
tags on the forums, to set certain parts a color.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
User avatar
Eamonn
Party member
Posts: 550
Joined: Sat May 04, 2013 1:29 pm
Location: Ireland

Re: Typo - Typewriter lib

Post by Eamonn »

davisdude wrote:I think what they mean is like how you use the

Code: Select all

[color][/color]
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 :D Thanks to telling me this though. I guess for the color tags I'd just need to add a parser of some sort, right?
"In those quiet moments, you come into my mind" - Liam Reilly
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: Typo - Typewriter lib

Post 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.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
User avatar
Sam Storms
Prole
Posts: 11
Joined: Tue Jul 15, 2014 6:39 pm

Re: Typo - Typewriter lib

Post by Sam Storms »

Very nice, I'm starting on a platformer, I'm gonna use typo on it :)
User avatar
Eamonn
Party member
Posts: 550
Joined: Sat May 04, 2013 1:29 pm
Location: Ireland

Re: Typo - Typewriter lib

Post 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 :awesome: ). Then you can add some more colorful things to your text.
"In those quiet moments, you come into my mind" - Liam Reilly
User avatar
Sam Storms
Prole
Posts: 11
Joined: Tue Jul 15, 2014 6:39 pm

Re: Typo - Typewriter lib

Post 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 :awesome: ). 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 :P
User avatar
Rukiri
Citizen
Posts: 68
Joined: Mon Jun 27, 2011 5:52 am

Re: Typo - Typewriter lib

Post 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 :awesome: ). 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?");
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests