How to use our fonts in GameMaker

Using our fonts in GameMaker: A screenshot of the GameMaker window with this title overlaid.

Ever wondered how you can use a custom font in GameMaker? Here’s a quick guide on how to load one of our fonts in GameMaker to use in your own projects.

Method 1: Import as a static resource

Step 1. Install the font on your PC

Open Windows Explorer to the place where you stored the font file, right-click the font file and select “Install” from the menu. The font will now be installed on Windows and become accessible in other programs. If GameMaker is already open, you will need to close it and re-open it to refresh the list of installed fonts.

Step 2. Create a new font resource in GameMaker

Open your project in GameMaker. Right-click the “Fonts” folder in the resource tree, hover over “Create” and then click “Font”. This will create a new font resource and open the font resource window.

Step 3. Select the font from the drop down list

Give your font resource a name (we’ve chosen fnt_main) and select the font you installed from the drop-down list next to “Select Font”. You can also change other options here such as the font’s style, size and whether or not to use anti-aliasing. For pixel fonts, you will want to turn anti-aliasing off.

Step 4. Add the character ranges you need for your game

GameMaker doesn’t include all of the characters in a font when you use this method, so you’ll need to click “Add” next to “Add new range” to add more characters. If you’re making a game in multiple European languages, you will need to click “ASCII” and then “Add Range” to make sure you have all the letters you need. Note: Different fonts support different varieties of letters. Some fonts may not include the letters you need.

Step 5. Set the font to be drawn in your code

When you want to use the font in your game, use the function draw_set_font to set the font before using the draw_text function.

// Set the font and draw some text
draw_set_font(fnt_main);
draw_text( 0, 0, "Hello World");

Now run the game and you’ll see the font in action!

Method 2: Load dynamically at run time

Step 1. Open the included files folder for your GameMaker project

Click the little hamburger menu in the top-right of the GameMaker resource tree and click “Included Files”. Then click the “Open in Explorer” button to open your project’s included files in Windows Explorer.

Step 2. Paste the font file in the folder

Move or copy the font file you downloaded into the included files folder in Windows Explorer.

Step 3. Load the font file at the start of your game

Use the font_add function to load the file at the very start of your game, for example in the game start event of an object. The first argument is the location of the font, so you should change this to the name of the font file you copied. Then you have size, bold, italic, first character and last character. To support the main European languages, first and last should be set to 0 and 255 respectively. Note: Different fonts support different varieties of letters. Some fonts may not include the letters you need.

// Add the font dynamically, and assign it to a global variable
global.my_font = font_add( working_directory+"Murphy's Folly.otf", 40, false, false, 0, 255);

You need to be careful loading fonts dynamically as they take up memory at run time. If you need to free up memory, you can use the font_delete command to unload a font you no longer need. You should take care not to load too many fonts at once in this way.

Step 4. Set the font to be drawn in your code

When you want to use the font in your game, use the function draw_set_font to set the font before using the draw_text function.

// Set the font and draw some text
draw_set_font(global.my_font);
draw_text( 0, 0, "Hello World");

Now run the game and you’ll see the font in action!

Which method is better?

In short, it depends on your game. Loading the font as a static resource allows you to control how much memory it’s using at run time. The font textures are generated at compile time, so you don’t need to worry about things like memory leaks. However, you’re stuck with whatever characters you added using “Add Range” in the GameMaker editor. Loading the font as a dynamic resource opens up potential issues with memory management, but GameMaker will automatically load characters from the font that you didn’t specify initially. This is useful if the player can choose between a variety of languages in the game.

We hope this guide has been helpful! You can download and try any of our fonts for free for non-commercial use on our fontspace profile, or you can buy our whole catalogue of fonts in our All Fonts Pack for commercial use here:

You may also like...