Select your Player Scene file
Another way to bring scenes into other scenes
Is to drag and drop them into the viewport
Do this with the coin.tscn
The coin will disappear when you move over it.
Add a TextureRect node as a child of Main
Add a Timer node as a child of Main
Objects are drawn in order from top to bottom
Drag the background up to be the first node under Main
Select the Background node
Drag grass.png from Assets to Texture
Change Stretch Mode to Tile
Attach a script to your Main node
Add variables to the script
@export makes the variables visible in the editor
Drag coin_scene.tscn into the new property
Godot calls _ready on every node as it is added to the scene tree
Anything you want to happen at the start should go here
We use the scene tree shortcut operator: $
To access nodes in the scene
The new_game function sets up everything for a new game.
Notice it calls a function to spawn coins.
We must now make this function.
In GDScript, writing for i in 5: repeats the code inside five times. By using level + 4, the game dynamically spawns more coins as the game gets harder (e.g., Level 1 spawns 1 + 4 = 5 coins, Level 2 spawns 2 + 4 = 6 coins).
Later we will call new_game() when the player clicks the start button on a menu screen.
For now add new_game() at the end of _ready(), press F6 to test the scene.