0 votes

I have the tree as:

Root
- gameLevel
-- HUD
---HBoxContainer

This is the code:

func drawLifeIndicators():
    var containerBox = get_node("HUD/HBoxContainer")
    var scene = load("res://batMini.tscn")
    var newBatMini
    for i in range(0, globals.lives):
        newBatMini = scene.instance()
        print("adding mini")
        #containerBox.add_spacer(true)
        containerBox.add_child(newBatMini)

If I check the inspector, yes, all 3 (in this case) life indicators show up as direct children of the HBoxContainer, BUT they all appear to be showing up in the same physical place. Can anyone see why they're being generated in the same position?

in Engine by (810 points)
edited by

What node types are your "life indicators"? If they are not Control-based (ie a 'green' node), they won't align themselves within a container.

Yes you were correct. I changed it to a control base and it NEARLY worked. Then by adding volzhs's answer to the solution it all came together. Thanks for the help.

1 Answer

+2 votes
Best answer

I guess root node of batMini.tscn is just Control node.
try to set min size of it in batMini.tscn
or set it with code newBatMini.set_custom_minimum_size(Vector2(width, height))

by (9,511 points)
selected by

Thank you, with a combination of your answer and YeOldeDM's answer it worked. Much appreciated.

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 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 webmaster@godotengine.org with your username.

Categories