Godot Version
4.6
Question
Right now, I have something like this. This is a stripped down version for simplicity:
Node scene_gun_1
- TextureRect for gun 1 (shows image of the gun)
- Label for gun 1’s HUD (shows ammo type and ammo count on HUD)
Node scene_gun_2
- TextureRect for gun 2
- Label for gun 2’s HUD
…
From here, I see that if I have many many more guns, I will have to repeatedly manually create a TextureRect and a Label for each gun scene, so I would like some advises on managing this programatically:
- From researching online, I see this could be done:
var new_label = Label.new()
new_label.text = "Hello World"
add_child(new_label)
And this should go into ready() function , and never init() , yes?
- I was thinking of creating each scene for each gun type, so there would be a pistol scene, shotgun scene, machine gun scene, etc. Each gun scene will house a different logic, so a pistol only fires one shot at a time, a shotgun spreads bullets around and a machine gun rapid fires. However:
from dynamically creating nodes above, perhaps a single scene could be used too, but then I still need to house the different logic for each gun type. Because of this, I am thinking of something like a general class that holds the logic for each generic type. For example, I could use a General_Pistol class that could allocate a TextureRect for a magnum pistol, a water pistol, etc. but they will all be under the General_Pistol class. So one scene could actually be used for many similar objects, given they will share the same logic.
Is this recommended or are there better design patterns out there?




