Creating complex scenes by composing with nodes
Godot Engine almost equally emphasizes the importance of both approaches, inheritance and composition. By default, you need to compose your scenes using the available default nodes. Then, you specialize, in other words, extend or inherit, them. For example, let’s understand how the player’s avatar scene was built up by a mix of these techniques. Usually, it all starts by laying down the general features using a composition of nodes, and then you extend their behaviors with scripts:

Figure 4.1 – The KingPigPlayer2D scene’s hierarchy composed of fifteen nodes
Notice that there are certain nodes and compositions that may not make sense at first glance, even the default ones. For instance, why don’t the Area2D
nodes allow us to set a Shape2D
directly? Why do we need to make a composition together with the CollisionShape2D
node? The simple answer is that this way the CollisionObject2D...