Dynamically created texture buttons?

GrampsGramps Posts: 4Member
in GUI

I've been trying to figure out how to dynamically create texture buttons for a bit now. There is nothing online about this. However, I have about 30 possible buttons that need to be created by script instead of just using the editor to make them, since they only show for specific things. Any ideas?

Answers

  • TwistedTwiglegTwistedTwigleg Posts: 494Moderator
    Answer ✓

    I have not made TextureButtons from code myself, but I have made some Control related nodes from script before. I did a quick test, and the code below works for me:

    var new_button = TextureButton.new();
    add_child(new_button);
    new_button.rect_size = Vector2(100, 30);
    new_button.rect_global_position = Vector2(80, 80);
    new_button.texture_normal = load("res://icon.png");
    new_button.connect("pressed", self, "button_pressed");
  • GrampsGramps Posts: 4Member

    Hey, thanks for the reply. That seems to work pretty well! Cheers!

Sign In or Register to comment.