Search code examples
game-makergml

How to make text change in game maker?


I have a text that appears, when the game starts. But once the obj_cover is destroyed, I would like another text to appear. So how can I do that?


Solution

  • If you want change one text to another, you can do something like

    if instance_exists(obj_cover)
        var txt = "text 1";
    else
        var txt = "text 2";
    
    draw_text(posx, posy, txt);
    

    If you want simple show text when obj_cover is destroyed, you can do, for example, this:

    Create object obj_text. Add to Create event:

    text = "";
    

    Draw event:

    // also here you can define color, font, align, etc
    draw_text(x, y, text);
    

    Now add to obj_cover, Destroy event:

    var obj = instance_create(posx, posy, obj_text);
    obj.text = "your text";
    

    Other way - you can use a variable for checking, is need draw text or not. For example, Destroy event of obj_cover:

    global.show_text = false;
    

    And somewhere in other object:

    if global.show_text
        draw_text(posx, posy, "text");
    

    etc... Very many ways possible.