June 2018
Beginner to intermediate
298 pages
7h 38m
English
Delete the extra nodes you added to your temporary Main.tscn (the Player instance and the test StaticBody2D). This scene will now be responsible for loading the current level. Before it can do that, however, you need an Autoload script to track the game state: variables such as current_level and other data that needs to be carried from scene to scene.
Add a new script called GameState.gd in the Script editor and add the following code:
extends Nodevar num_levels = 2var current_level = 1var game_scene = 'res://Main.tscn'var title_screen = 'res://ui/TitleScreen.tscn'func restart(): get_tree().change_scene(title_screen)func next_level(): current_level += 1 if current_level <= num_levels: get_tree().reload_current_scene()
Note that ...
Read now
Unlock full access