GMS 2.3+ Problems with draw_text()

Awnser228

Member
I'm having some trouble with the draw_text() method:
I'm trying to create a GUI which opens when the shift key is pressed and closes when it's let go:

GML:
if (!global.moving)
{
    //Check for the shift key being pressed and check there isn't already a menu up
    if keyboard_check(vk_shift) && !global.menupresent
    {   
        global.menupresent = true;
        gui = layer_sprite_create("GUI",gui_x,gui_y,spr_gui);
        draw_text(gui_x,gui_y-180, "Menu");
    }
    if !keyboard_check(vk_shift) && global.menupresent
    {
        global.menupresent = false;
        layer_sprite_destroy(spellcastinggui);
    }
}
Most of these shouldn't need too much explanation but just in case:
global.moving is a Boolean that represents if the player is currently changing position
gui_x,gui_y are pre-defined ints just to put the gui in the centre of the screen.
And this is all done in a "Draw GUI" event.

My problem is that the text does appear, but only for a few frames, and then it disappears. The sprite remains, it's just the text. Can anyone explain why this is happening? And how I might go about fixing it?
 
It's because you lumped in the text with the menu creation, and because you only do that once, the text only draws once.

GML:
if (!global.moving)
{
    //Check for the shift key being pressed and check there isn't already a menu up
    if (keyboard_check(vk_shift))
    {
        if (!global.menupresent)
        {
            global.menupresent = true;
            gui = layer_sprite_create("GUI",gui_x,gui_y,spr_gui);
        }

        draw_text(gui_x,gui_y-180, "Menu");
    }
    else if (global.menupresent)
    {
        global.menupresent = false;
        layer_sprite_destroy(spellcastinggui);
    }
}
 

Awnser228

Member
It's because you lumped in the text with the menu creation, and because you only do that once, the text only draws once.

GML:
if (!global.moving)
{
    //Check for the shift key being pressed and check there isn't already a menu up
    if (keyboard_check(vk_shift))
    {
        if (!global.menupresent)
        {
            global.menupresent = true;
            gui = layer_sprite_create("GUI",gui_x,gui_y,spr_gui);
        }

        draw_text(gui_x,gui_y-180, "Menu");
    }
    else if (global.menupresent)
    {
        global.menupresent = false;
        layer_sprite_destroy(spellcastinggui);
    }
}
Ahhhhh thank you very much; so drawing is frame-based process, not a continuous state. Good to bear in mind for the future.
 
Top