What is a Node?
What is a Node?
A node is a fundamental element in Godot.
A node is a fundamental element in Godot.
Everything in a Godot project, such as the player, enemies, environments, lights, backgrounds, and camera, is made up of nodes.
Nodes can have children nodes, which can have children nodes, and so on.
This creates a hierarchy of nodes, which is the basis of a Godot game.
Add a child node by pressing the plus
Add a child node by pressing the plus
Select a Sprite2D
Select a Sprite2D
New Scene Tree:
New Scene Tree:
Rename the node to Player
Rename the node to Player
Drag and drop the Player.png
Drag and drop the Player.png
To the Texture property
To the Texture property
Of the Sprite2D (Player) node.
Of the Sprite2D (Player) node.
Player appears
Player appears
In the Scene's viewport
In the Scene's viewport
In the Transform property,
In the Transform property,
found in the Inspector window,
found in the Inspector window,
you can modify the position, rotation,
you can modify the position, rotation,
and scale of the Player sprite.
and scale of the Player sprite.
If you change any of the values
If you change any of the values
you will notice they update inside the
you will notice they update inside the
Viewport window.
Viewport window.
For example, setting the position to (50, 0)
For example, setting the position to (50, 0)
will move it 50 pixels to the right.
will move it 50 pixels to the right.
On the other hand, setting the position to (-150, 0)
On the other hand, setting the position to (-150, 0)
will move it 150 pixels to the left of the center of the graph.
will move it 150 pixels to the left of the center of the graph.
What is a Scene?
What is a Scene?
Scenes are collections of nodes that can be instanced (created/spawned) at any time.
Scenes are collections of nodes that can be instanced (created/spawned) at any time.
For example: levels in a game can be their own scene.
The player can be a scene that is instanced/spawned in multiple levels.
Enemies can also be saved as a scene and spawned in multiple times.
In our TestScene level is a Player node,
In our TestScene level is a Player node,
We might also want other objects,
We might also want other objects,
like rocks, trees, or enemies.
like rocks, trees, or enemies.
Let's make our Player part of their own scene
Let's make our Player part of their own scene
so that we can reuse it and edit is separately
so that we can reuse it and edit is separately
to the rest of the game world and objects.
to the rest of the game world and objects.
This concept is similar to Prefabs in Unity.
This concept is similar to Prefabs in Unity.
Right-click on the Player Node
Right-click on the Player Node
Scroll-down and select Save Branch as Scene
Scroll-down and select Save Branch as Scene
Save the Scene as Player.
Save the Scene as Player.
Double-click the Player Scene in the FileSystem.
Double-click the Player Scene in the FileSystem.
It will open in a new tab in the Viewport.
It will open in a new tab in the Viewport.
Return to your TestScene tab.
Return to your TestScene tab.
Drag and drop a few Player Scenes into the TestScene viewport.
Drag and drop a few Player Scenes into the TestScene viewport.
You are creating multiple player instances (copies)
You are creating multiple player instances (copies)
Now return to your Player Scene.
Now return to your Player Scene.
Change the colour of the Player
Change the colour of the Player
By Selecting Visibility and then
By Selecting Visibility and then
adjusting the modulate property.
adjusting the modulate property.
The colour of the player changes in its scene.
The colour of the player changes in its scene.
Save the Player Scene
Save the Player Scene
by pressing CTRL+S
by pressing CTRL+S
and return to the TestScene.
and return to the TestScene.
Now all the instances have changed colour.
Now all the instances have changed colour.
Any changes we make to the Player scene affect all of the instances!
Any changes we make to the Player scene affect all of the instances!
What happens when we add nodes to the Player Scene?
What happens when we add nodes to the Player Scene?
In the Player Scene
In the Player Scene
Right-Click the Root Node (Player)
Right-Click the Root Node (Player)
Select Add Child Node
Select Add Child Node
Select Sprite2D
Select Sprite2D
Rename the Node to Coin
Rename the Node to Coin
Use the Coin.png as the Texture.
Use the Coin.png as the Texture.
Change the Transform - Position of the coin to 0x and -50y
Change the Transform - Position of the coin to 0x and -50y
This places the coin above the players head.
This places the coin above the players head.
Save Player Scene and return to TestScene.
Save Player Scene and return to TestScene.
Every player instance will now have a coin above its head.
Every player instance will now have a coin above its head.