how to make a side scrolling game in scratch

Mastering Scratch: Creating Your First Side-Scrolling Game

By Andrew Williams
AD

Creating a side-scrolling game in Scratch can be an exciting and rewarding endeavor. Scratch, a visual programming platform designed by MIT, is perfect for beginners looking to dip their toes into game development. Today, we'll guide you through the process of making a side-scrolling game, step by step.

Side-scrolling games, often referred to as platformers, involve a character moving horizontally across the screen. Games like Super Mario Bros. and Sonic the Hedgehog are classic examples of this genre. By the end of this tutorial, you'll have a basic understanding of how to create one in Scratch.

The Basics: Setting Up Your Stage

First, let's set up our stage. In Scratch, click on 'Create' to start a new project. An empty stage will open up, where you'll create your game.

AD
How to Make a Zombie Survival Game in Scratch!!!
How to Make a Zombie Survival Game in Scratch!!!
Build a Space Invaders Game in Scratch 3.0 | Free Coding Tutorial ⭐
Build a Space Invaders Game in Scratch 3.0 | Free Coding Tutorial ⭐
Free, Ready to Use, Scratch Lesson!
Free, Ready to Use, Scratch Lesson!

To make it a side-scrolling game, you'll need to resize your stage. Click on 'Stage Properties' (the button with a square and arrow), then change the size to 800 pixels wide and 600 pixels tall. This will give you enough room to work with.

Creating the Main Character

Time to create our hero! Click on the 'Choose a Sprite' button, and select a character sprite. For this example, we'll use the classic 'dancer' sprite.

an open world in scratch is shown
an open world in scratch is shown
How To Make A Space Shooter/Rock Blaster Game In Scratch!
How To Make A Space Shooter/Rock Blaster Game In Scratch!
How to Make a Scrolling Background in Scratch | Tutorial
How to Make a Scrolling Background in Scratch | Tutorial

Double-click on the sprite to open the ‘Costumes' editor. You can customize your sprite here, but let's keep it simple for now. Click 'OK' to save.

Setting Up the Scene

Now, create the background for our game. Click on 'Choose a Backdrop', and select the 'Cast' backdrop. This will give us a generic game scene.

AD

Again, double-click on the backdrop to open the ‘Backdrops' editor. You can customize this as well, adding platforms, enemies, or other obstacles. Once done, click 'OK' to save.

How to Make a Jumping Game in Scratch | Tutorial
How to Make a Jumping Game in Scratch | Tutorial
an apple game is shown on the screen, and it's instructions are in english
an apple game is shown on the screen, and it's instructions are in english
How to Make a Zombie Survival Game in Scratch!!!
How to Make a Zombie Survival Game in Scratch!!!
Scratch 3.0 Tutorial: How to Make a Racing Game in Scratch (Part 1)
Scratch 3.0 Tutorial: How to Make a Racing Game in Scratch (Part 1)
Scratch Tutorial for Kids: Rocket Landing
Scratch Tutorial for Kids: Rocket Landing
RPG Tutorial | Craft your dream Scratch Game | 1. The Player ⛹️
RPG Tutorial | Craft your dream Scratch Game | 1. The Player ⛹️

Making Our Character Move Sideways

This is where the fun begins! We'll use the keyboard to control our character's horizontal movement.

Click on 'Events' in the toolbox, then drag the 'when key pressed' event to the script area. Next, click on 'Controls' and drag 'change x by' to the script area. Joining these two blocks together should look like this:

AD
  • when key pressed
  • change x by (Concat: 10) // 'Concat: 10' means 'concatenate 10' - it adds 10 to the current x position

Making Our Character Move Left

To make the character move left, we need to modify our script slightly. Click on the 'change x by' block, and change the value from '10' to '-10'. This will subtract 10 from the current x position.

Let's Build: How to #code a Scrolling Background with #parallax #effect in #scratch - Part 2
Let's Build: How to #code a Scrolling Background with #parallax #effect in #scratch - Part 2
Make an Easy Mario Platformer Game on Scratch
Make an Easy Mario Platformer Game on Scratch

Now, to complete our script, we need the character to move in the opposite direction when the left arrow key is pressed. Repeat the above steps, but this time, connect the 'when key pressed?' event to the 'change x by' block with '-'10'. Make sure the left arrow key is selected in the 'key' dropdown.

Adding Boundaries to the Stage

Finally, we need to ensure our character doesn't move off the stage. Click on 'Controls', and drag the 'set x to' block to the script area. This block will limit the character's movement to the stage width. Connect the 'when flag clicked' event to the block, set the 'x' value to '0', and the 'y' value to '0'. This will reset the character's position when the game starts.

AD

Next, add another 'set x to' block, but this time, set the 'x' value to '-10'. Connect this to the 'when key pressed' event with the right arrow key selected. This will prevent the character from moving further right than the stage.

Testing and Improving Your Game

Now, click the green flag to test your game. Your character should now move left and right across the stage.

Once you're happy with the basics, you can build upon this foundation. Add platforms, enemies, and collectibles. Create a script to detect collisions. You might even want to create additional levels, each with its own backdrop and challenges.

Remember, game development is a process of iteration. Don't be discouraged if your first attempts aren't perfect. Keep refining your game, and most importantly, have fun!

AD