GMS 2 [SOLVED] Draw text on object doesnt work

Discussion in 'Programming' started by JND_3004, Sep 12, 2019.

  1. JND_3004

    JND_3004 Member

    Joined:
    Sep 12, 2019
    Posts:
    9
    Hi Guys,

    In my script, two objects are placed in a desired position.
    After both have been placed, a text is to be generated. However, my text is never created. There are no error messages.

    All arguments are given and set.

    I hope you can help me on.

    My Code
    Code:
    floorDefault_x = argument0;
    floorDefault_y = argument1;
    floorBackground_x = floorDefault_x + 160;
    floorBackground_y = floorDefault_y + 16;
    floorName_x = floorDefault_x + 268;
    floorName_y = floorDefault_y + 3;
    objName = argument2;
    floorName = string_upper(argument3);
    
    instance_create_layer(floorDefault_x, floorDefault_y, "FloorsCreated", obj_floorDefault);
    instance_create_layer(floorBackground_x, floorBackground_y, "FloorsCreated", objName);
    
    draw_set_color(c_white);
    draw_set_alpha(1);
    draw_set_font(CourierNew);
    draw_set_halign(fa_left);
    draw_text(floorName_x, floorName_y, string(floorName));
     
  2. Greenwitch

    Greenwitch Member

    Joined:
    Aug 30, 2019
    Posts:
    7
    Draw functions need to be done inside of draw events, otherwise nothing's happening.
     
  3. Alexx

    Alexx Member

    Joined:
    Jun 21, 2016
    Posts:
    430
    What event is the code in?

    Drawing code needs to be in a Draw Event.
     
  4. JND_3004

    JND_3004 Member

    Joined:
    Sep 12, 2019
    Posts:
    9
    And how do I start the certain event?

    Because the script as only executed where both objects are created (works well) and additionally only a text should be created.
    I thought it would generally be enough to use draw_text().
     
  5. JND_3004

    JND_3004 Member

    Joined:
    Sep 12, 2019
    Posts:
    9
    Even if I want to insert a text via DnD, he writes draw_text(). GMS2 does not create a draw event itself and there is no button for a draw event.
     
  6. Alexx

    Alexx Member

    Joined:
    Jun 21, 2016
    Posts:
    430
    You can add a Draw Event here:
    [​IMG]
     
  7. JND_3004

    JND_3004 Member

    Joined:
    Sep 12, 2019
    Posts:
    9
    OK thanks.

    However, I can not combine it with my script, right?
    Because when scripting and certain events, the script is executed. Since I can work badly with the draw event again ..

    Finally, I would like to do everything in the script and not write about many detours.
     
  8. Alexx

    Alexx Member

    Joined:
    Jun 21, 2016
    Posts:
    430
    Then call the script from a Draw Event, though note that only drawing code should be in it. Other code should be in a Step Event. I'd personally split into 2 scripts and call them separately.
     
  9. JND_3004

    JND_3004 Member

    Joined:
    Sep 12, 2019
    Posts:
    9
    In principle, it works for me, but my object has a sprite, and once an event exists with content, the sprite is no longer shown, but only the draw event.
    What can this be?
    Can objects with sprites contain no events?
     
  10. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,589
    Adding a Draw event disables the default sprite drawing.

    Re-enable it by calling draw_self() inside the Draw event.
     
  11. JND_3004

    JND_3004 Member

    Joined:
    Sep 12, 2019
    Posts:
    9
    Perfect, thank you and the others.
    Then this problem is done for the first :)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice