font_add_sprite_ext

Creates a new font resource based on a sprite with the sub-images ordered by a string, and returns its index.

Syntax:

font_add_sprite_ext(spr, string_map, prop, sep);


Argument Description
spr The sprite to add a font based on.
string_map String from which sprite sub-image order is taken.
prop Set as proportional font or not.
sep The space to leave between each letter.


Returns: Real


Description

With this function you can use a "sprite strip" (the sprite itself must be a sprite asset from the resource tree, or a sprite you have added to the game resources using sprite_add) to create a new font asset, where each sub-image would be an individual symbol or letter. Unlike the normal font_add_sprite which has a specific order for the sub-images of the sprite, this function will map the sprite sub-images based on the argument "string_map" of the function. This argument is a string that you can use to tell GameMaker: Studio what order the sub-images of the sprite font are and it will map these automatically when writing text. So, for example, if you have a string-map of "AaBbCcDdEeFfGgHh", your sprite font must have the sub-images ordered in this way.

You can also set the spacing for the font to be proportional (true) or not (false), where a proportional font is spaced based on the actual width of the letters (so the letter "i" takes less room than the letter "w", for example) while a non-proportional font will be spaced based on the sub-image width, like a monospaced font. Finally, you can define the space to leave between each letter when writing, and this can be any integer value, with 0 being no space (the letters will "touch" if proportional). 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.

NOTE: When you load a font into GameMaker: 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.


Example:

global.Font = font_add_sprite_ext(spr_CalcFont, "0123456789+-*/=", true, 2);

The above code will create a new font asset from the sprite indexed in the variable "spr_CalcFont" and store the index of the new font in the variable "global.Font". The sub-images of the sprite font will be mapped to the string specified.


Back: Fonts
Next: font_replace
© Copyright YoYo Games Ltd. 2015 All Rights Reserved