GameMaker [Solved] Text size adapted in a box

R

RobotoSkunk

Guest
Hi, how can I make a text adapt its X and Y scale within a limited space? Because I tried to do it and I just can not. What should I do?

Code:
draw_self();
draw_set_halign(fa_center);
draw_set_font(fnt_pixelman);
xt = x+lengthdir_x(15*image_xscale, image_angle+90);
yt = y+lengthdir_y(15*image_yscale, image_angle+90);
if(string_width(tt) > 100){
    width -= 0.05;
}
switch(type){
    case 0:
        draw_text_transformed(xt, yt, string_hash_to_newline(text[1]), image_xscale*width, image_yscale*width, image_angle);
        break;
    case 1:
        draw_text_transformed(xt, yt, string_hash_to_newline(text[2]), image_xscale*width, image_yscale*width, image_angle);
        break;
    case 2:
        draw_text_transformed(xt, yt, string_hash_to_newline(text[3]), image_xscale*width, image_yscale*width, image_angle);
        break;
    case 3:
        draw_text_transformed(xt, yt, string_hash_to_newline(text[8]), image_xscale*width, image_yscale*width, image_angle);
        break;
}
draw_set_halign(-1);
draw_set_font(-1);
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
the scale would be min(1, string_width(text) / maxwidth, string_height(text) / maxheight)
 
R

RobotoSkunk

Guest
the scale would be min(1, string_width(text) / maxwidth, string_height(text) / maxheight)
Code:
if(string_width(tt) > sprite_width){
    width = image_xscale-min(image_xscale, string_width(tt)*image_xscale/sprite_width*image_xscale, string_height(tt)*image_xscale/sprite_width*image_xscale);
} else {
    width = image_xscale;
}
I just repaired it, also thanks for answering because that way you gave me a good idea to solve my bug ^^
 
Top