Home | Customize | Blog | Extras | Log In | Info
Manual | D&D icons | GML Parser | Archive | Iso City
Username: Password:  
About | Features | Directory | Banners | Contact

Designing Games with GameMaker
Designing Games with GameMaker

Fonts and text

In games you sometimes need to draw texts. To draw a text you have to specify the font to use. Fonts can be defined by creating font resources (either in the GameMaker program or using the functions to create resources). There are different functions to draw texts in different way. In each function you specify the position of the text on the screen. There are two functions to set the horizontal and vertical alignment of the text with respect to that position.

For text drawing the following functions exist:

draw_set_font(font) Sets the font that will be used when drawing text. Use -1 to set the default font (Arial 12).
draw_set_halign(halign) Sets the horizontal alignment used when drawing text. Choose one of the following constants as values:

fa_left
fa_center
fa_right

draw_set_valign(valign) Sets the vertical alignment used when drawing text. Choose one of the following constants as values:

fa_top
fa_middle
fa_bottom

draw_text(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. (Use \# to get the # symbol itself.)
draw_text_ext(x,y,string,sep,w) Similar to the previous routine but you can specify two more things. First of all, sep indicates the separation distance between the lines of text in a multiline text. Use -1 to get the default distance. Use w to indicate the width of the text in pixels. Lines that are longer than this width are split- up at spaces or - signs. Use -1 to not split up lines.
string_width(string) Width of the string in the current font as it would be drawn using the draw_text() function. Can be used for precisely positioning graphics.
string_height(string) Height of the string in the current font as it would be drawn using the draw_text() function.
string_width_ext(string,sep,w) Width of the string in the current font as it would be drawn using the draw_text_ext() function. Can be used for precisely positioning graphics.
string_height_ext(string,sep,w) Height of the string in the current font as it would be drawn using the draw_text_ext() function.

The following routines allow you to draw scaled and rotated text and also to use gradient colors on texts. These functions are only available in the Standard Edition!

draw_text_transformed(x,y,string,xscale,yscale,angle) Draws the string at position (x,y) in the same way as above, but scale it horizontally and vertically with the indicated factors and rotate it counter-clockwise over angle degrees.
draw_text_ext_transformed(x,y,string,sep,w,xscale,yscale,angle) Combines the function draw_text_ext and draw_text_transformed. It makes it possible to draw a multi-line text rotated and scaled.
draw_text_color(x,y,string,c1,c2,c3,c4,alpha) Draws the string at position (x,y) like above. The four colors specify the colors of the top-left, top-right, bottom-right, and bottom-left corner of the text. alpha is the alpha transparency to be used (0-1).
draw_text_ext_color(x,y,string,sep,w,c1,c2,c3,c4,alpha) Similar to draw_text_ext() but with colored vertices.
draw_text_transformed_color(x,y,string,xscale,yscale,angle,c1,c2,c3,c4,alpha) Similar to draw_text_transformed() but with colored vertices.
draw_text_ext_transformed_color(x,y,string,sep,w,xscale,yscale,angle,c1,c2,c3,c4,alpha) Similar to draw_text_ext_transformed() but with colored vertices.

Search Search


Alternative versions Alternative versions

You can also read this manual on one single long page (± 1.5 mb)

Also available in: Dutch French German

ZIP Download helpfile

Advertisement Advertisement

GameMaker Manual