This function will replace a sprite font that you created previously using the function font_add_sprite_ext. It uses a "sprite strip", where each sub-image is be an individual symbol or letter, and the images are mapped to letters based on the argument "string_map" of the function. This argument is a string that you can use to tell GameMaker Studio 2 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: This function requires you to have previously added a sprite font using font_add_sprite(), as it will replace that and cannot be used on fonts that are included as part of the game resources.
重要!该函数在试用版(Trial License)产品中可用。


font_replace_sprite_ext(font, spr, string_map, prop, sep);

参数 描述
font The font to replace.
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.




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

The above code will replace a sprite font asset that is indexed in the variable "global.Font" with sprite images indexed in the variable "spr_CalcFont".