+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?

asked Jun 28, 2019 in Engine by websterek (228 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)
answered Jun 29, 2019 by Dlean Jeans (3,911 points)
selected Jun 29, 2019 by websterek
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.