Draw Text in a Circle in GameMaker

How to draw text in a circle in GameMaker

One effect that can elevate your game to a higher level is drawing your text in a circle. Whether you’re using it for a dynamic user interface, or some piece of background scenery, this simple script will help you out!

With draw_text_circle you can choose: the size of the circle, whether the text is inside or outside of the circle, the direction and the starting angle. Here’s the script:

/// @description draw_text_circle(x,y,str,radius,outin,firstchardir,clockwise)
/// @param x
/// @param y
/// @param str
/// @param radius
/// @param outin
/// @param firstchardir
/// @param clockwise
function draw_text_circle(argument0, argument1, argument2, argument3, argument4, argument5, argument6) {

	var originx = argument0; // Where you want the centre of the circle to be (x coordinate)
	var originy = argument1; // Where you want the centre of the circle to be (y coordinate)
	var msg = argument2; // What you want the circle text to say. Leave a space at the end of the string for clarity.
	var radius = argument3; // How far from the central point you want the text to be drawn
	var outin = argument4; // Whether you want the text to face outwards (0) or inwards (1)
	var facing = (outin) ? 90 : 270;
	var initdir = argument5; // The initial direction of the first character in the text string
	var clockwise = (argument6) ? -1 : 1; // Whether the text reads clockwise (true) or anti-clockwise (false)

	// Align the text to the center
	draw_set_halign(fa_center);
	draw_set_valign(fa_middle);

	// Set up some variables before opening the loop
	var s = string_length(msg) // String length
	var dangle = initdir; // Angle to increment
	var angdiff = 360 / max(s,1); // Distance between letters

	for (var i=0;i<s;i++) {
		
		draw_text_transformed( originx + lengthdir_x( radius, dangle), originy + lengthdir_y( radius, dangle), string_char_at(msg, i+1), 1, 1, facing + dangle);
		dangle += angdiff*clockwise;
		
	}

	draw_set_color(c_white)

}

By changing the starting angle of the text dynamically, you can even create a scrolling effect where the text goes around and around in circles, like I used in my game Quickly! Makebones.

Here are some more screenshots of the script in action:

Feel free to copy & paste the code from above, or download the .yyz GameMaker template from the link below.

Allison

Allison

Font and game designer since 2003. She/her. Pong Quest, Vermin Vibes, Maddening & more 🏳‍🌈 Normally in my Discord server Harts Bluff where we play BOTC, Jackbox, GeoGuessr etc.

Leave a Reply