Search code examples
fontsgame-makergml

Fonts issue in game maker 1.2


im trying to use more than one font in GM, but when using draw_set_font in a draw event both of my drawed fonts becomes the same, even though i'm using draw_set_font in two different objects.Please, how can i do to solve this?

Here is the first object, called hud:

if(global.dead == false){
    //Draw health bar
    draw_sprite(spr_hearts, global.hp, 10,10)
    //Set score
    //draw_set_color(c_white)
    //draw_set_font(fnt_main)
} else {
    draw_text((room_width/2) - 30,room_height/2-30 , "GAME")
    draw_text((room_width/2) - 25,room_height/2 , "OVER")
}

Here is the second, called obj_score:

draw_set_color(c_white)
draw_set_font(fnt_score)
draw_text(140,10,"SCORE : " + string(global.score))

Solution

  • draw_set_font(), draw_set_colour(), etc. functions change the global state of the graphics pipeline. It's not independent for every object. So, object hud should be like:

    if !global.dead
    {
        // Draw health bar
        draw_sprite(spr_hearts, global.hp, 10, 10);
    }
    else
    {
        draw_set_color(c_white); 
        draw_set_font(fnt_main);
        draw_set_halign(fa_center);
        draw_set_valign(fa_middle);
        draw_text(room_width div 2, room_height div 2, "GAME#OVER"); // or "GAME\nOVER" for GMS2
    }
    

    And obj_score:

    draw_set_color(c_white);
    draw_set_font(fnt_score);
    draw_set_halign(fa_left);
    draw_set_valign(fa_top);
    draw_text(140, 10, "SCORE : " + string(global.score));
    

    or if you want it together:

    draw_set_color(c_white); 
    draw_set_font(fnt_score);
    draw_set_halign(fa_left);
    draw_set_valign(fa_top);
    draw_text(140, 10, "SCORE : " + string(global.score));
    
    draw_set_font(fnt_main);
    draw_set_halign(fa_center);
    draw_set_valign(fa_middle);
    draw_text(room_width div 2, room_height div 2, "GAME#OVER");