GameMaker [SOLVED} Font Size - How do I enlarge fonts?

E

EricR175

Guest
Hello,

This is only my second post so far since starting to use Gamemaker Studio 2, which I love. I'm trying to learn as much as I can without help so that I remember things that I discover. I always find that if you discover things on your own, you will remember better.

However, I want to draw text, which I already know how to do :), but I also want to manipulate the size of the font. I know all of the font functions like color and draw, however, is there a way to size the font?

I know it will only draw basic fonts from the computer unless I include a font which needs permission from the font owner.

Do I have to use number sprites and do more coding? I'm pretty sure that I can code it to use sprites as numbers but I would rather just use arial.
 

ZeDuval

Member
You need to add the font with the specific size to the resource tree individually for every size you want to use(as far as I know?!).
Let's say you want Arial 10,12 and 14, add the 3 fonts to your project and name them fn_arial10, fn_arial12,...
In the beginning of your game, initialize a global var:
Code:
global.current_font = "fn_arial"; // string
Create 2 scripts:
Code:
/// draw_set_font_ext(font,size) // string,real
global.current_font = "fn_"+argument[0];
if argument_count==2 draw_set_size(argument[1]);
Code:
/// draw_set_size(size) // real
var font = asset_get_index(global.current_font+string(argument0));
if font_exists(font){
  draw_set_font(font);
  return true;
}
Then you can use it like this in the Draw event:
Code:
draw_set_font_ext("arial",10);
draw_text(32,32,"Small");
draw_set_size(14);
draw_text(32,64,"Large");
The idea isn't perfect or finished but it's a start to build on and meant more as an inspiration. ;) I still need to finish and release an extension of mine based on this concept + bold, italic,...
 
S

Samwiz1

Guest
You need to add the font with the specific size to the resource tree individually for every size you want to use(as far as I know?!).
Let's say you want Arial 10,12 and 14, add the 3 fonts to your project and name them fn_arial10, fn_arial12,...
In the beginning of your game, initialize a global var:
Code:
global.current_font = "fn_arial"; // string
Create 2 scripts:
Code:
/// draw_set_font_ext(font,size) // string,real
global.current_font = "fn_"+argument[0];
if argument_count==2 draw_set_size(argument[1]);
Code:
/// draw_set_size(size) // real
var font = asset_get_index(global.current_font+string(argument0));
if font_exists(font){
  draw_set_font(font);
  return true;
}
Then you can use it like this in the Draw event:
Code:
draw_set_font_ext("arial",10);
draw_text(32,32,"Small");
draw_set_size(14);
draw_text(32,64,"Large");
The idea isn't perfect or finished but it's a start to build on and meant more as an inspiration. ;) I still need to finish and release an extension of mine based on this concept + bold, italic,...

Hi. I found this page because i had a similar problem, and because i'm trying to get textbox text to change fontsize even while it's still printing i thought i'd give it a shot. But this is a GMS2 thread, and there's no draw_set_size string?...
If you could clarify on that or maybe point me in the direction of how to get that in my gamemaker 2 i'd appreciate it, because i need what you typed to work :p
 
and there's no draw_set_size string?
If you read that post a bit closer you will see that the "draw_set_size" is a script that they have clearly shown in the post you quoted. @ZeDuval even shows exactly what you need to do to get it to work: create 3 fonts at different sizes, then create the scripts and then use them in the Draw Event.
 
Top