Connecting Levels
Connecting Levels
Section titled Connecting LevelsNow let’s create a trigger to load the next level.
-
In Level1 add a new Area2D node (rename to EndArea) and give it a CollisionShape2D as a child (rename to Collider).
-
On the EndArea node, change the collision mask to only have 2 selected.
-
Give the Collider a shape and place it where you’d like the end of the level to be.
-
Attach a script to the Level1 node, then click on the new Area2D node you just made and connect the “body_entered” signal to Level1. Change the code to this:
extends Node2D## Base level 1 scriptconst LEVEL2 = preload("res://Scenes/level_2.tscn")# Change to next level when player finishes the level by reaching the EndArea areafunc _on_end_area_body_entered(_body: Node2D) -> void:get_tree().change_scene_to_packed(LEVEL2) -
You can make another scene called Level2 and create a new level with different platforms, enemies, items, and maybe different tiles. Once you’ve done that, when you reach the end of Level1, it will load Level2 and you can play it.
Next Steps
Section titled Next StepsCongratulations, you now have a working 2D platformer. Here is a list of possible extensions you might want to add to your game:
- Investigate adding moving platforms using AnimationPlayers
- Killing enemies if you jump on them or some form of combat
- On screen health or life system
- On screen timer or score
- Game over screen
- Messing with tile collisions to create secret areas