- Title: When draw_text draws nothing; ten things to check
- Description: A brief check list for troubleshooting draw_text
- GM Version: Any version (GM5 and later)
- Registered: No
- File Type: N/A
- File Size: N/A
- File Link: N/A
- Required Extensions: none
- Required DLLs: none
You may experience that no text shows up on the screen when you use draw_text for the first time (or the corresponding action
1. it is in the DRAW event
Usually, all of drawing commands must be executed in the draw event. (There are some techniques to draw things in other place, e.g. pause screens, but it's another story.)
2. the object is in the room
An instance of the object that has the draw event must be placed in the room. (This is kind of obvious but is often overlooked.)
3. it is visible
An instance should be visible, or its draw event isn't executed. Open the object properties and make sure that the checkbox "Visible" is ticked.
4. it is drawn inside the visible area
It sometimes happens that you accidentally put wrong coordinates, making the text appear far out of screen. Try changing x and y into something like (10, 10) or (view_xview[0]+10, view_yview[0]+10) to see if it appears in view. Also, check out that it isn't sticking out of the border of the view because of the text alignment settings (draw_set_halign and draw_set_valign.)
5. it isn't drawn with zero alpha
Graphics properties are global settings. When you use a command to change some of graphics settings (e.g. draw_set_color, draw_set_alpha and so on), it affects on every drawings until you change the settings again. It so happens that you execute draw_set_alpha(0) in another object that makes your text transparent.
It is advised to set graphics settings back when you finish drawing:
draw_set_alpha(some_variable); // draw things using alpha draw_set_alpha(1); // Set it back when finishedOr set it to default in prior to every drawings:
draw_set_alpha(1); // Ensure to set it to the default value draw_text(x, y, text);
6. the font contains necessary characters
If you're using a custom font to draw the text, open the font properties to check the settings of "Character Range." For instance, if you want to draw numbers and alphabets, it should contain both ranges of Digits (48 till 57) and Letters (65 till 122.) If in doubt, just choose "Normal" (32 till 127.)
7. it isn't hidden behind other things
Make sure that your text isn't hidden behind other drawings. If there is other object at the same place, make sure that the object to draw the text has smaller depth than the other one. In case you draw multiple things within one object, make sure that draw_text comes later.
draw_sprite(sprite, -1, x, y); // Draw the background of text first... draw_text(x, y, text); // Then draw the text on it.If you have backgrounds in the room, make sure that you didn't accidentally tick "Foreground image" to make it cover everything.
8. the text isn't empty
If you store the text in a variable, make sure that its contents isn't empty at the moment when the draw event is executed.
9. draw_text is actually executed
Sometimes it turns out that draw_text is not executed at all; either the code exits before it reaches to the line of draw_text, or it is inside some control statement (if, for, while and so on) and the body is not executed. To check this, you can put a debug message like this:
if (some_condition) {
show_debug_message("draw_text is executed.");
draw_text(x, y, text);
}Then run the game with debug mode, open "Show Message" window to see if the debug message appears there.10. it isn't drawn with the same color as the background
This may sound silly, but human makes this sort of mistake. Try to draw a black rectangle behind the text, then change it into white to see if it makes your text rise to the surface.
Appendix: my sprite disappears when I draw a text!
Game Maker automatically draws an object's sprite only when its draw event is empty. If you draw something in the draw event and want to preserve the sprite, you have to draw it on your own.
draw_sprite(sprite_index, -1, x, y); // Draw the object's sprite... draw_text(x, y, text); // Then draw the textNote that draw_sprite ignores any of special settings (scale, alpha transparency, rotation and blend color.) If you need those properties, use draw_sprite_ext instead. (Alternatively, you can use draw_self if you have GM 8.1 or later.)
draw_sprite_ext(sprite_index, -1, x, y, image_xscale, image_yscale, image_angle, image_blend, image_alpha); draw_text(x, y, text);











