This function can be used to add a font to your game from those fonts that are installed on the system it is running on. You can define the size of the font (in points), as well as whether the font should be bold or italic, and you can also define the range of characters to include (for a full table of available characters and their UTF8 value see Font tables). The function returns an index value that should be stored in a variable as this will be needed in all further codes that refer to this font.
For the HTML5 target module, this function can only be used to add Web Fonts, and will only work if WebGL is not enabled - if WebGL is enabled then you must use a general font resource (ie: using draw_set_font along with a font from the resource tree) or bitmap fonts (see font_add_sprite).IMPORTANT! When targeting HTML5, italics and bold text is only supported if the font asset or web font itself has these characters included. They will not be synthesised from the base font.
The following table shows the fonts that are standard across all browsers and that should be be available for use without problems. Any other font may or may not exist on the computer or device that is running your game, so the use of this function should be limited to these standard fonts:
Windows Font Name Mac Font Name Font Family Arial Arial / Helvetica sans-serif Arial Black Arial Black / Gadget sans-serif Comic Sans MS Comic Sans MS cursive Courier New Courier New monospaced Georgia Georgia serif Impact Impact / Charcoal sans-serif Lucida Console Monaco monospaced Lucida Sans Unicode Lucida Grande sans-serif Palatino Linotype / Book Antiqua Palatino serif Tahoma Geneva sans-serif Times New Roman Times New Roman / Times serif Trebuchet MS Trebuchet MS sans-serif Verdana Verdana / Geneva sans-serif Georgia Georgia serif Symbol Symbol N/A Webdings Webdings N/A Wingdings Zapf Dingbats N/A MS Sans Serif Geneva sans-serif MS Serif New York sans-serif
On all other (non Web) targets, you can use this function to add a font from a file. The file must be included in the game bundle using the Included Files functionality of GameMaker Studio 2, and must be a *.ttf format font file, useful for adding non-standard fonts like Asian or Arabic.WARNING!: If you include a font in *.ttf format with a game, it must be licensed for distribution with the game.
When loading a font from a file in this way the size of the font is in pixels and the first and last values are ignored, meaning all glyphs in the font will be added. Fonts added in this way are assigned to their own texture page, so care should be taken when using this function as it will increment the number of texture swaps when drawing. It is also worth noting that fonts may appear slightly larger when drawn, since glyphs may have parts that are drawn outside of the bounding box defined for the font. You should be aware too that there is a limitation of around 200 glyphs that can be rendered in a single frame for a particular font.NOTE: When you load a font into GameMaker Studio 2: Studio you must remember to remove it again (with font_delete) when no longer needed, otherwise there is risk of a memory leak which will slow down and eventually crash your game.
font_add(name, size, bold, italic, first, last);
Argument Description name The name of the font to be added (eg 'Arial'), or the file path if the font is an included *.ttf file. size The size of the font - points for Web Fonts, pixels for *.ttf fonts. bold Whether the font is bold (true) or not (false). italics Whether the font is italic (true) or not (false). first The first character to include (if you're unsure, go for 32). last The last character to include (if you're unsure, go for 128).
newfont = font_add("Arial", 24, true, true, 32,
This will create a new font that is 24pt in size, uses "Arial" which is bold and italic and the index for this new font is stored in the variable "newfont". The font range includes capital and lower case letters, numbers and all common punctuation.