October 4, 2024

How to Build a Platformer: Switching Levels

Create a game without coding skills!
CREATE A GAME NOW

This tutorial was put together by our community member shawnBuilds for Rosebud AI, the AI-powered game creation platform. Check out shawn’s games here, and join our Discord to find more tutorials and connect with other creators!

Right now, we only have one level in our platformer, and when you complete it, the game just restarts. That’s no fun!

Let’s fix that by adding another level and setting up transitions from one level to the next. You can check out the final version of the game to see these level transitions in action.

Quickstart

You can create your own project on Rosebud to follow along.

We’ll be adding onto a platformer with one level, where the player can fetch a key and bring it to the door to complete the level. This is the most recent version of the game from my platformer tutorial series, so even if you haven’t been following along, you can start right here. Here’s how:

  1. Open the Rosebud Setup Project Link to access the project.
  2. Click the remix button in Rosebud to create your own version of the game.

Once you’ve got the game set up, you’re ready to start adding levels and transitions!

Loading the New Level

Let’s get started by adding a new level to our game, level 0. Once this level is loaded, we can later switch to level 1, which has been used for gameplay so far. We'll use a new level data file to load level 0, which will tell our game where to put everything in the level.

Message to Rosie

Let's add a new level to the game, level 0, and begin the game from this new level. For now, we won’t switch to the next level, level 1, when the game is completed.Use the level data file from the link below to load level 0:- 'level00': [level00.json](https://play.rosebud.ai/assets/level00.json?hacl)

After applying the code from Rosie, check your game. Level 0 should appear when the game starts. Once you unlock the door with the key, level 0 should restart.

Switching to the Next Level

Now that we have level 0 and level 1 loaded in our game, we're ready to set up level transitions.

When a player completes a level, the game should transition to the next level. We’ll make sure to clean up the current level to prepare the game for the next one. This includes removing things like coins and keys.

When the final level is completed, we’ll loop the game back to level 0. Usually, a game would transition to a final game screen, but that’s outside the scope of this tutorial. Looping back to the beginning will make sure the player can keep playing after beating the game.

Message to Rosie

Let's switch to the next level when a level is completed.
Before loading the next level, clean up the current level so things like coins and keys are removed.
Since we don't have a game complete screen, if the final level is completed, we'll load the very first level, level 0.

After applying the code from Rosie, check your game. When a level is completed, it should transition to the next one. If the final level is completed, the game should loop back to level 0.

Checklist

  • Level 0 loads when the game starts.
  • When the player completes a level, the game transitions to the next level.
  • If the player finishes the final level, the game loops back to level 0.
  • Coins and keys are cleared from the previous level when moving to the next.
  • If the player dies, the current level restarts.

Game

Here’s the final game we’ve built, where the player can now transition smoothly between levels and restart the game after completing the final level:

Platformer - Switching Levels

Wrapping Up

Now your platformer has a new level, and transitions between levels when the player fetches the key and unlocks the door!

We started by using a level data file to set up a new level, level 0. Then, you added the transition from level 0 to level 1, and made sure the game restarts when the player completes the final level.

It’s been a lot of fun building this platformer with you. The complete How to Build a Platformer tutorial is coming soon!

Ready to turn your ideas into games?
GET STARTED NOW