Hello and welcome to another episode in the Godot basics tutorial series.
In this episode we will be taking a quick look at nodes and scenes to refresh your memory from the GDScript fundamental tutorial series. We know that a node class inherits from the Object class. Therefore it does not remove itself from memory even if nothing is referenced to it. However. If a note is removed from the scene it will cue itself for memory release and it will do the same for. All. Its children. Now unlike the node class nodes are something completely different nodes
Are the core Of Godot. As a matter of fact all games are based on nodes and scenes. Now a node by itself is useless so matter of fact. You'll find with good dough that you'll need to combine multiple nodes together in order to get certain functionality. Nodes can also have multiple nodes underneath them. And as a matter of fact this results in a tree like structure. So one rule to know is that a single node can have multiple children but multiple children
Can Only have one parent. And on top of that the nodes and the children need to have their own unique. Names. So again nodes need to have one parent and this is where we get our tree like structure. It's a matter of fact a node without a parent is called the root node and on top of that nodes inherently transforms of their parents. You can consider that the parent position as the origin the origin that all children nodes revolve around. So one thing to note is that the root gnome should manage creation and deletion of their children on top of that all scenes need a root node.
You can also think of a root node as a manager class. Basically you manage the creation and deletion of your child nodes. Now this is what a Node tree and scene looks like.
So you can see here we have the seen tab the plus sign allows us to add new nodes onto the scene and on top of that.
You can only have one root node which is again a node without a parent. And notice how we have children. In this case the No to decode can a magic parent. Sprite child and collision child. And just from the look of this image we can see the tree like structure where our root nodes are beginning and everything. Basically branches out from there. One thing to note is that nodes are drawn in tree orders. We will get to take a look at this in a future episode. However just note that as long as your notice towards the bottom in the tree like structure of seen the nodes towards the bottom have priority in the drawing sequence over the top.
So let's go ahead and take a look at that. Let's pretend all of these nodes are actually sprites.
We'll just use our imagination for now but our tree structure is the same. Let's go ahead and take a look at an example. So imagine each of these nodes has an image and our tree structure is the same as the previous slide.
Well first what we do is we grab our first node in the scene and we go ahead and draw that on our game and then we move down the line and we draw that next.
And we draw the third one next. The fourth one next. And the last thing to be drawn to the scene will be number 5 and whatever image is in our node at the fifth level will be at the front of the game in terms of priority and the image that was drawn first.
In this case the root node will be drawn in the back because it was drawn first and therefore everything drawn after that gets drawn on top of a root node.
Let's go ahead and talk about scenes.
So a tree of nodes is called a scene and every scene must have one root on top of that scenes can be safe to disk and instanced in two other scenes. As a matter of fact if you want to run a game you must have at least one scene moving on a single project can have multiple scenes and on top of that scenes can be switched loaded and reloaded.
Now to add a new scene that we can add nodes to we need to create a file with the file name extension dot t s scene and that would be short for text scene.
Now one cool feature is that we can use a scene tree to organize our nodes into groups and other game engines such as unity we would call that a prefab and on top of groups we can actually create something called groups which will take a look at in a future episode.
So why are scenes important. Well for one thing. We can create proper games and I put proper in quotations and as a matter of fact a proper game is whatever game you want to make over if you plan on selling on iOS or Android. They are expecting a more rounded sand all the edges kind of game.
And so let's go ahead and take a look at that name again in quotations proper game we have a splash screen can have your company image or the Godot logo. And from there we move into our main menu scene and that holds all of our buttons
Gives us or rather it gives the player choices to pick what to do and the player can choose to one play the game by entering the game scene or perhaps they want to look at credit.
And so they choose to go into the scrolling credit scene.
As you can see we can use scenes to make a more rounded kind of game. And games can even have scenes inside of them. So think of a game like Mario and when you press play you enter the Mario World. You pick your level and the level picker is your scene.
Right. World One World two. And then once you pick your world or rather once you pick your level you enter another scene. And that's the level you are playing. So that's just an example of how we can use scenes to create games. So far we just went over theory and the next episode we will look into the scene system. Now
That's all I have for you in this episode. Thank you so much for joining me. If you have any questions or comments please feel free to leave them in the comments section down below.
I look forward to seeing you in the next episode.
Have an amazing day