What you'll build and what you need
A platformer is a game where a character moves left and right across the screen, jumps over obstacles, and avoids enemies — think of classic games like Super Mario Bros. In Scratch, you can build a working platformer in an afternoon using the visual block system, which means you don't write code in text form. You'll create a player character that responds to keyboard input, add gravity so it falls when it jumps, place platforms to stand on, and add straightforward enemies or obstacles.
You need a free Scratch account at scratch.mit.edu, a web browser, and about two hours. Scratch runs in your browser on Windows, Mac, or Linux. No software installation required. You can use the built-in sprite library (pre-made characters and objects) or draw your own straightforward shapes.
Key Takeaways
- Start by creating a player sprite and adding blocks that make it move left and right when you press arrow keys.
- Add gravity by decreasing the y-position every frame so the character falls, then stop it when it touches a platform.
- Build platforms as separate sprites or use a painted background, and detect when the player lands on them to stop the fall.
- Test constantly — run your game after each new block you add so you catch problems early.
- Add enemies or obstacles last, after movement and jumping work smoothly.
Setting up your player character and keyboard controls
Open Scratch and create a new project. Delete the default cat sprite by right-clicking it and selecting Delete. Click the sprite icon to add a new sprite from the library. Choose a character — the Sprite1 character works well for beginners. This becomes your player.
Click the Code tab for your sprite. From the Events category, drag a "when green flag clicked" block to the workspace — this runs your code when you press the green play button. Under Control, add a "forever" loop below it. This loop runs your movement code over and over, many times per second.
Inside the forever loop, add blocks from the Sensing category: "if key [space] pressed then". Change "space" to "right arrow". Inside that if-block, add a Motion block: "change x by 10". This moves the player 10 pixels right when you hold the right arrow. Duplicate this block and change it to "left arrow" with "change x by -10" to move left. Now test by clicking the green flag and pressing arrow keys — your character should slide across the screen.
Adding gravity and jumping
Real platformers don't let the character slide in mid-air — gravity pulls them down. Create a new variable called "velocity_y" by going to Variables and clicking Make a Variable. In your forever loop, add "change velocity_y by -0.5" — this increases downward speed each frame. Then add "change y by velocity_y" to actually move the character down.
When the player lands on a platform, velocity_y should reset to zero so they stop falling. You'll handle this in the next section. For now, add a straightforward boundary: if the player falls below the bottom of the screen, reset them to the top. Add "if y < -180 then set y to 180" inside your forever loop.
To jump, add another keyboard check: "if key [space] pressed then set velocity_y to 15". This gives an upward push. Test this — the character should fall constantly and jump when you press space. The jump won't feel right yet because there's no platform to land on, so the character will fall forever and reset.
Creating platforms and detecting collisions
Platforms are the surfaces your player stands on. The simplest approach is to paint them into the background. Click the Stage (the white area to the left of your sprites list). Click the Backdrops tab, then Edit. Use the rectangle tool to draw brown or green rectangles at different heights — these are your platforms. Make them wide enough to land on. Save this backdrop.
Now you need to detect when the player touches a platform. This is called collision detection. In your player's forever loop, add a Sensing block: "if touching color [brown]?" and inside it, set "velocity_y to 0". This stops the player from falling when they touch a platform color. Test by clicking the green flag — your character should now fall until it hits a platform, then stop.
Adjust the platform positions and sizes until jumping and landing feel natural. If the character gets stuck in a platform, add "change y by -2" inside the collision block to push them up slightly. This prevents the player from sinking into the platform.
Adding obstacles and enemies
Once movement works smoothly, add obstacles to make the game challenging. Create a new sprite for an enemy — choose something straightforward like a Crab or Bat from the library. Position it on the screen. Add a forever loop that makes it move back and forth: "change x by 2", then "if x > 240 then set x to -240". This makes the enemy patrol across the screen.
Add a collision check in your player's forever loop: "if touching [enemy sprite name] then set y to 180". This resets the player to the top when they hit an enemy, like losing a life. You can add more enemies by duplicating the sprite and changing their starting positions and speeds.
You can also add spikes or hazards by painting them into the background and checking for the same color collision as platforms — but reset the player instead of stopping them.
Testing and improving your game
Play your game after every change. Does the character move smoothly? Does jumping feel responsive? Do platforms feel solid? If the character moves too fast or too slow, adjust the "change x by" values — higher numbers mean faster movement. If gravity feels wrong, change the -0.5 value — more negative means faster falling.
Common problems: the character gets stuck in platforms (add the "change y by -2" fix mentioned earlier), jumping feels floaty (increase the jump velocity from 15 to 20), or the character slides off platforms too easily (make platforms wider). Scratch lets you pause the game by clicking the red stop button, then click the green flag to restart and test your fix.
Add more platforms at different heights to create a level. Duplicate enemies and place them in different spots. You can add a score variable and increase it when the player touches certain sprites, or add a timer to see how fast you can complete the level.
Sharing and next steps
When your platformer works, click Share at the top to publish it. Other Scratch users can play it and leave comments. You can also read it as a file to keep a backup.
Once you're comfortable with basic platformers, try adding new features: a double-jump (check if the player is touching a platform before allowing another jump), moving platforms that carry the player, or a goal sprite that ends the level. Each feature uses the same blocks you've already learned — just in new combinations.
Frequently Asked Questions
How do I make my character face the direction it's moving?
In the Motion category, use "point in direction 90" for right and "point in direction -90" for left. Add these blocks inside your keyboard checks. Your sprite will flip automatically when you change direction.
Can I add sound effects when the player jumps?
Yes. In the Sound category, add "play sound [pop]" inside your jump block. Scratch has built-in sounds, or you can record your own. The sound plays when ready when you press space.
What if my character falls through a platform sometimes?
This happens when the character moves too fast and skips over the collision check. Reduce the jump velocity or the gravity value. You can also add a second collision check: "if y > [platform y position] and y < [platform y position + 20]" to catch faster movement.
How do I make a level that scrolls instead of staying in one view?
Instead of moving the player sprite, move the background and all platforms in the opposite direction. When the player reaches the middle of the screen, add "change x by -[player speed]" to all platform sprites. This creates the illusion of the camera following the player.
Can I add a pause button?
Yes. Create a new variable called "paused". Add a keyboard check: "if key [p] pressed then set paused to not paused". Wrap your forever loop in "if not paused then" — this stops all movement when paused is true.