0

Why is this first creating a correctly size button with the correct number but the wrong background colour and text colour and then the correct button(everything) is created and how can I fix it?

func _pressed():
    var newTile=Button.new()
    newTile.set_script(nT)
    newTile.rect_min_size=Vector2(75,75)
    spawnpoint=spawnlocn-Vector2(25,25)
    newTile._init3(spawnpoint,num,Color( 0.75, 0.75, 0.75, 3))
    newTile.set_global_position(spawnpoint)
    newTile.text=str(num)
    newTile.add_color_override("font_color",Color( 0.75, 0.75, 0.75, 3))
    var stylebox_flat := StyleBoxFlat.new()
    stylebox_flat.bg_color =Color(1, 1, 1, 1)
    newTile.add_stylebox_override("normal", stylebox_flat)
    get_parent().add_child(newTile)
user2617804
  • 169
  • 1
  • 2
  • 12
  • I believe what you are seeing is the `newTile` button in a different state than "normal". Hovered, pressed, focused, and disabled are other states of a button. Each state has their own font and stylebox overrides. Try setting the other state overrides and see if this is the issue. – hola Nov 16 '21 at 00:13
  • Additionally, you may find it helpful to [create a theme](https://docs.godotengine.org/en/stable/tutorials/gui/gui_using_theme_editor.html) and either assign it to the button via script or a parent of the buttons. – hola Nov 16 '21 at 00:16
  • You forced by GODOT to have Hovered, focused .etc signals and states. I sent a proposal and they refuse to fix it. – user2617804 Nov 18 '21 at 09:03

0 Answers0