Using [font_add_sprite_ext]

I asked about fonts some time ago at the Game Design, Development and Publishing . I wanted to use font_add_sprite_ext but I had concerns about the memory leak risk.

Then I was I told that I can add and store the font in a global variable when the game starts, then the font will be available throughout the game.

I have a "sprite sheet" - as the manual says. However, I realize I don't really know how to accomplish what was suggested to me.

I ask for some assistance.

Please be my torch, guide me through the dark.
 
G

Gaspode

Guest
I'm new to GM:S so I hope this is right, as I've used global fonts in my app.

In my init script for the app I do this...

Code:
global.fntDotsNum = font_add_sprite_ext(sprFntDotsNum, "0123456789.:ABCDEFGHIJKLMNOPQRSTUVWXYZ", true, 1);
where sprtFntDotsNum is the name of the sprite sheet.

Then in my draw event for the text object, I do:

Code:
    draw_set_halign(fa_center);
    draw_set_valign(fa_top);
    draw_set_color(c_yellow);
    draw_set_font(global.fntDotsNum);
    draw_text(x, y, "Some text");
Hope this helps...
 

NightFrost

Member
Just as Gaspode said, and if you don't yet know how to correctly bring in your font asset, you have to use "Create from Strip..." from file dropdown in the sprite editor. In other words, your font sheet needs to be like an animated sprite, with each letter a separate subimage. Their order must match the order in the text string you supply to font_add_sprite_ext.
 
Last edited:
Top