Shaking text

M

McGamesC

Guest
Well... i need to do a shaking text that every letter shakes apart from the rest (like Undertale) and i found a guy that posted a shaking text but it wasn't letter by letter, i tried EVERYTHING (changing that system) and i get something that don't works well (it's a bit bugged and the text writes backwards, ex: i write "Hello" and it puts "olleH" so i need to put the original text backwards) and now i get that it works well (letter by letter, no bugs) but the text behind the actual letter dissapear, like: "H" "-e" "--l" "---l" "----o" instead of "H" "He" "Hel"... and that.
So if someone could help me i would be very grateful :)

my code is: (for the first dialog,the bugged but semi-working one.)

//CREATE event

ind=0
str2="any text but backwards."


alarm[0]=6


//ALARM 0 event

if ind < string_length (str2){
ind+=1
}
alarm[0]=6

//DRAW event

draw_x=x+15
draw_y=y+15

for(i=1;i<=length;i+=1){
str=string_copy(str2,i,1);
length_so_far=string_width(string_copy(str2,i,ind));
draw_set_font(fnt_text)
draw_set_color(c_white)
draw_text(draw_x+length_so_far+random_range(-intensity,intensity),draw_y+random_range(-intensity,intensity),str);
}


(for the second dialog, the letter skipping one.)

//CREATE event
str2="Any normal text";
ind=0
alarm[0]=6

//ALARM 0 event

if ind < string_length (str2){
ind+=1
sound_play(voice)
}
alarm[0]=6

//DRAW event
for(i=1;i<=length;i+=1){
str=string_copy(str2,ind,1);
length_so_far=string_width(string_copy(str2,i,ind));
draw_set_font(fnt_texts)
draw_set_color(c_white)
draw_text(draw_x+length_so_far+random_range(-intensity,intensity),draw_y+random_range(-intensity,intensity),string_copy(str,i,ind));

}


Please... help, i'd literally tried everything, changing values, positions for the code, changing i for ind or a number, please c:
 

CloseRange

Member
in all your code i never know where 'length' comes from in the draw event. I assume you left out a lot of code? I would normally just tell you where to change your code but I don't understand a lot of where these variables come from or go so I'll just show you how I'd do it:

Code:
/// Create Event
text = "any text";
char = 0;
char_time = 6;
intensity = 5;

alarm[0] = char_time;
Code:
/// alarm[0]
if(++char < string_length(text))
    alarm[0] = char_time;
sound_play(voice);
Code:
/// draw event
draw_set_font(fnt_texts);
draw_set_color(c_white);

var tx = x+15;
var ty = y+15;
for(var i=0; i<char; i++) {
    var c = string_copy(text, i+1, 1);
    var rx = random_range(-intensity, intensity);
    var ry = random_range(-intensity, intensity);
    draw_text(tx+rx, ty+ry, c);
    tx += string_width(c);
}
 
M

McGamesC

Guest
It worked fine, thanks! and yes... i miss the length variable (but in the code it was right) it's just the variable length = string_length(string(str2))

Also i'm working on GM8.1 so i modified a bit the code because it wasn't working, but thanks! :D



Edit: I tried to put a line break on it and i can't, i used #, i used draw_text_ext... etc. if there's any way to do it... if not, well, doesn't matter.
 
Last edited by a moderator:

Gamebot

Member
# Should work. If you know ahead of time the way you want your text I believe you can just put them on separate lines and it will work. So...

Create:
text = "Hello.
How are you?"

Should draw on the screen:

Hello.
How are you?

Though its been a while for 8.0 / 8.1
 
M

McGamesC

Guest
Mmm... not working, i think it's because the string_copy() but idk
 

CloseRange

Member
@McGamesC
ahhhhh sorry it took so long to reply D: very busy few days no time to code.
where you have draw_text replace it with this
Code:
if(c == "#") {
    ty += string_height(c);
    tx = x+15;
} else
    draw_text(tx+rx, ty+ry, c);
# didn't work before because this draws every character individually. what I just added adjusts the y and resets the x
 
Top