+1 vote

I'm trying to use draw_char function in godot for debugger, it seems to be the best options for me instead of labels but... I don't known how to use it :(

My code looks like that:

draw_char(font, pos, "Test_1", "Test_2", Color(1, 0, 0))

where font is get_font("font") from Control and pos is position unprojected from camera. Circles are drawing correctly but text is invisible.

How to properly use this function?

in Engine by (227 points)

1 Answer

+1 vote
Best answer

The correct way to draw a string withdraw_char:

func _draw():
    var font = load('res://Font.tres')
    var pos = Vector2(500, 500)
    var string = 'Test'

    for i in string.length():
        var c = string[i]
        var next_char = string[i + 1] if i + 1 < string.length() else ''
        var advance = draw_char(font, pos, c, next_char, Color.red)
        pos.x += advance

draw_char only draws one-character string, which is why you don't see anything.

I don't recommend using this for drawing a string, but instead use draw_string:

draw_string(font, pos, 'Test', Color.red)
by (4,037 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.