0 votes

I'm wanting to create code in GDscript that populates a horizontal container with the sprites in scenes. These scenes are stored in an array. I got the panels working, but I'm not sure how to go about moving/adding the sprite to the created panel, or if this is even possible. This is what I have:

extends HBoxContainer
export (Array, PackedScene) var Arsenal 

onready var panel = load("res://src/GUI/ArsenalPanel.tscn")

func _ready():
        for x in Arsenal:
            var panel_inst = panel.instance()
            var scene_inst = x.instance()
            var sprite = scene_inst.get_node("Base") # the sprite to display

            sprite.centered = false
            add_child(panel_inst)
Godot version 3.3.3
in Engine by (33 points)

1 Answer

+1 vote
Best answer

I'm guessing you want a new node for each panel? Just call .duplicate() on the sprite to get a new node, and then add it as a child to the panel.

by (8,528 points)
selected by

Yes! Ahg I'm facepalming because I didn't realize you could just call the add_child function from the instance; I misunderstood add_child_below_node by thinking 'below node' meant you selected a node for the object to be a child of. Instead, it's the order of children. Thanks!

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.