How to Make Subway Surfers - Scratch 3.0 Tutorial - Episode 2
Table of Contents
Introduction
In this tutorial, we will learn how to create a scrolling background in Scratch 3.0, similar to the game Subway Surfers. We will use clones and a unique MOD block to enhance the gameplay. Additionally, we will implement a size hack to allow sprites to move off-screen, add multiple truck costumes, and introduce a ground pound feature for better player control.
Step 1: Setting Up the Scrolling Background
-
Create the Background:
- Open Scratch and create a new project.
- Choose a suitable background that resembles the Subway Surfers environment.
- Import your background image or draw one using the Scratch editor.
-
Add Clones for Continuous Scrolling:
- Select the background sprite and add a script to create clones:
- Use the
when green flag clicked
event. - Create a loop to generate clones continuously.
- Use the
- Example code:
when green flag clicked forever create clone of [myself v] wait (2) seconds
- Select the background sprite and add a script to create clones:
-
Manage Clones:
- In the clone's script, ensure that it moves down the screen to create a scrolling effect:
- Use the
when I start as a clone
block. - Move the clone downwards and reset its position when it goes off-screen.
- Use the
- In the clone's script, ensure that it moves down the screen to create a scrolling effect:
Step 2: Implementing the Size Hack
-
Using the Size Hack:
- Adjust the size of your sprites to allow them to move off-screen:
- Set the sprite's size to a small percentage (e.g., 10%).
- This allows for better gameplay as sprites can extend beyond the visible area without being cut off.
- Adjust the size of your sprites to allow them to move off-screen:
-
Control the Size Dynamically:
- You can use a variable to control the size dynamically:
- Create a variable named
sizeFactor
. - Set
sizeFactor
to a low value (like 10). - Use it to adjust the size of the sprite when it spawns.
- Create a variable named
- You can use a variable to control the size dynamically:
Step 3: Adding Truck Costumes
-
Create Multiple Truck Costumes:
- Import various truck images to your project.
- Make sure each truck sprite has a different costume.
-
Switching Between Costumes:
- In your truck sprite's script, randomly choose a costume each time a truck is spawned:
- Use the
switch costume to [costume v]
block within the clone script.
- Use the
- Example code:
when I start as a clone switch costume to (pick random [1 v] to [number of costumes v])
- In your truck sprite's script, randomly choose a costume each time a truck is spawned:
Step 4: Implementing Ground Pound Feature
-
Creating the Ground Pound Mechanic:
- Add a new sprite for the ground pound effect.
- Create a script that detects when the player presses a specific key (e.g., spacebar) to trigger the ground pound.
- Example code:
when [space v] key pressed create clone of [ground pound effect v]
-
Control Player Movement:
- Modify the player sprite's script to allow for a fast fall when the spacebar is pressed.
- Ensure the falling speed is increased temporarily to simulate a ground pound effect.
Conclusion
In this tutorial, we covered the essential steps to create a Subway Surfers-style scrolling background in Scratch 3.0. We learned how to use clones for continuous movement, implement a size hack for dynamic gameplay, add various truck costumes, and introduce a ground pound feature for enhanced player control.
Next steps could include refining the player controls, adding obstacles, and implementing scoring mechanics to further develop your game. Happy coding!