Draw Text Gamemaker


At some time when making your game you will need to use text. Text in games is dealt with by using the string functions (a string is just another way of saying a line of text) and GameMaker Studio 2 has a complete set of functions that permit you to manipulate strings in many ways, including the insertion of one string in another, the copying of strings and the ability to parse strings for the.

  • 75 votes, 15 comments. 54.6k members in the gamemaker community. This subreddit is dedicated to providing programmer support for the game.
  • Drawtext(x,y,string) Draws the string at position (x,y), using the drawing color and alpha. A # symbol or carriage return chr(13) or linefeed chr(10) are interpreted as newline characters. In this way you can draw multi-line texts. GameMaker.info is an independent site and is not endorsed by The GameMaker.

You’ve made a game and it’s going well, but you need to add a save feature so that the player can continue with their adventure – ini functions will do the trick.

ini functions use an ini file to store numerical and string values which can be written to the file and read later on. Let’s see how we can save a simple thing in an ini file – let’s take the score of the game.

Saving the score

First, let’s create a save button, and when clicked, it will save the score. Add the Left Pressed event and add a code action.

For this, we’ll use the ini_open function. It will create an ini file if there isn’t one already, and open it if it’s already there.

We’ve specified the ini file name here. As the game probably doesn’t have this ini file already, it will create it and open it. Now we’ll write the score variable to the ini file. For this, I assume that the score is saved in a global hitScore variable. You can change it accordingly.

A global variable is a variable which can be read and changed by any object. A normal variable can be used by any object too, but for that you need to put in the name of the object having the variable (like obj_player.hitScore to use a normal variable).

This function writes a numerical value to the ini file. Since our hitScore stores a numerical value, we’ll use this function and not the string variant of it.

In an ini file, there are keys which store the value, and sections which store the keys. Here savegame is the section in the ini file I will create which will store the key score which stores my hitScore value.

This functions saves your changes to the ini file and closes it. Now we’re done with this code.

Draw Text Gamemaker

Now lets create a new Load button and add some code in its Left Pressed event so that we can use it to load our score.

Okay, this is almost similar to our previous code. The first line opens the savedata.ini file we created first. In the second line, we are reading the hitScore value using ini_read_real() which we saved last and then assigning it to the variable hitScore. This will change our score in-game.

In ini_read_real(), we have first specified the section to look in, then the key to look for, and then the “default” value which is the value given to the hitScore variable if no save is found.

And then, ini_close() to close the ini file.

Try it in your game! Make some score, save it, re-start the game, and load the score!

Saving player location

Suppose I have a player with the variables hitScore (stores the score), playerLevel (stores the level of the player) and playerName (stores the name in a string). Now when I save the game, I want to save these things:

Draw Text Game Maker

  • Player’s location
  • Player’s score and level
  • Player’s name

To save the player’s location, we’ll save the room id and x/y locations so that we can load them. For score and level, we’ll use ini_write_real() as we did above, and for the name we’ll use ini_write_string() which stores a string value.

Gamemaker Draw Text

Here I assume our player’s object as obj_player. We’ll use the variables from the obj_player object. Let’s create a Save button object and add some code:

If you didn’t know already, text after the // is called a comment, and it has no effect on the code – it’s just a comment, plain text where you can write anything you want.


This is pretty much self-explanatory, so let’s move on and create a Load object. Here’s the code for the Load object:

This is simpler than it looks. For the most part, we’re reading the values we previously saved and assigning it to variables which belong to obj_player – that’s why every variable has obj_player. before it.

I created a variable roomID at the start and then used it to store the room ID read from the ini file. Then after closing the ini file, I used room_goto() to move to the room stored in the variable. Simple, isn’t it? 😉


Combine Strings Gamemaker


Draw Text Transform Text Gamemaker

It’s really this easy to save information about your game and load it later on. As stated in the GMS documentation, ini files work on almost all platforms. Using ini functions you can store any value so if used nicely, this is a pretty useful thing.

Gamemaker Draw_text Transformed Color

Thanks for reading, have a great day and happy game-making!

Game Maker 2 Draw Text

P.S. Any suggestions/questions? Comment below and I’ll get back to you ASAP!