Hello,
I try to create a label with some additional functionality by extending from the Label class:
# file: ColorLabel.gd
extends Label
var color
var count
var is_checked
func _init(clr, cnt):
color = clr
count = cnt
._init()
func _ready():
set_text(str(count))
add_color_override("font_color", color)
I create such aColorLabel
and add them to their parent node, but they do not show up on the screen:
const ColorLabel = preload("res://ColorLabel.gd")
# ...
var label = ColorLabel.new(count, color)
# set position, etc.
add_child(label)
When I instead use a usual Label
object, everyhing "works" as expected (i.e. the label shows up on screen, with the proper color, etc.):
var label = Label.new()
label.set_text(str(count))
label.add_color_override("font_color", color)
# set position, etc.
add_child(label)
Of course thats a workaround, but then I need to keep track of the color and the count in another way, so I would prefer the custom class.
Is it possible to derive from a control in such a way, and if yes, why does the custom label not show up?