draw_char how to use that

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By websterek

Hi!
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 :frowning:

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?

:bust_in_silhouette: Reply From: Dlean Jeans

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)

Hi, in my tests I cannot find a purpose for using the next_char. It has no affect on the advance value or what is drawn. I would like to know what it is for please.

Andrew Wilkes | 2022-09-11 10:54