How to Create Flappy Bird on Scratch: A Step-by-Step Guide
Scratch is one of the most accessible platforms for learning game development, and recreating Flappy Bird is a classic beginner-to-intermediate project that teaches core programming concepts like gravity, collision detection, and score tracking. Here's how the whole thing fits together.
What You're Actually Building
Flappy Bird is mechanically simple: a bird falls continuously due to gravity, the player taps to give it upward momentum, and pipes scroll from right to left. Touch a pipe or the ground — game over. That simplicity is exactly why it's such a useful Scratch project. You're working with loops, conditionals, variables, and sprite cloning — the building blocks of almost every 2D game.
Setting Up Your Scratch Project
Start at scratch.mit.edu and create a new project. You'll need at least three sprites:
- The Bird — your player character
- The Pipe — used as a cloned obstacle
- A Ground or Floor — optional but useful for collision
For the backdrop, a simple scrolling sky or a solid color works fine. You can draw your own sprites using Scratch's built-in editor or import images.
🐦 Programming the Bird: Gravity and Flap
The core mechanic is a physics simulation using variables. You don't need real physics — just the appearance of it.
Create a variable called velocity. In the bird's script:
- When the green flag is clicked, set
velocityto0and position the bird near the center-left of the screen. - In a forever loop, continuously add a gravity value (try
-1or-0.5) tovelocity, then change the bird's Y position byvelocity. - When the spacebar is pressed (or screen is clicked), set
velocityto a positive number like8or10— this is the "flap."
The interaction between gravity dragging velocity down and the flap pushing it up creates the characteristic arc that defines Flappy Bird's feel. Adjusting the gravity and flap values dramatically changes difficulty, so experiment here before building further.
Building the Pipes: Cloning and Randomness
Pipes are where Scratch's clone feature becomes essential. Rather than creating dozens of separate pipe sprites, you use one pipe sprite and clone it repeatedly.
Here's the general approach:
- Hide the original pipe sprite when the flag is clicked.
- Use a loop that creates a new clone every 2–3 seconds.
- Each clone appears at the right edge of the screen (
X = 240) at a random Y position, creating the gap variation. - In the clone's own script, it glides or moves left using a
change X by -3loop until it reaches the left edge, then deletes itself.
The gap between the top and bottom pipe is critical. A common method is to use two separate pipe sprites — one for the top, one for the bottom — and offset their Y positions using a shared random variable so the gap always aligns. Alternatively, a single tall sprite with a gap drawn into it can work, but positioning becomes trickier.
Collision Detection
Scratch uses a touching color or touching [sprite] block for collisions. You'll want:
- If the bird touches the pipe sprite → trigger game over
- If the bird touches the ground (bottom of screen or a floor sprite) → trigger game over
- If the bird goes above the top of the screen → also trigger game over
For game over, a clean approach is broadcasting a game over message that stops other scripts and shows a restart option.
🏆 Tracking Score
Score in Flappy Bird increments each time the bird successfully passes a pipe. In Scratch, you can detect this by checking when a pipe's X position crosses the bird's X position:
- Create a
scorevariable - In the pipe clone's script, add a check: when
X position < bird's X positionand the score hasn't been counted for this clone yet, increase score by 1
A boolean variable per clone (like scored) prevents the score from incrementing multiple times for the same pipe.
Key Variables That Affect Your Build
| Variable | Effect | Typical Range |
|---|---|---|
| Gravity strength | How fast the bird falls | -0.3 to -1.5 |
| Flap velocity | How high each flap goes | 6 to 12 |
| Pipe speed | How fast pipes move | 2 to 5 |
| Pipe gap size | Difficulty of navigation | 80 to 150 pixels |
| Pipe spawn rate | How often pipes appear | 1.5 to 3 seconds |
These aren't universal standards — they're the tuning dials of your game's feel.
Where Skill Level Changes the Approach
A first-time Scratch user will likely manage the basics — bird movement, a single moving pipe, and a simple collision. The project is completable in an afternoon with patience.
An intermediate builder can layer in pipe randomization, clone management, a proper score counter, sound effects (Scratch has a built-in library), and a start screen.
A more experienced programmer on Scratch might add increasing difficulty over time, parallax scrolling backgrounds, high score saving using cloud variables, or mobile-style tap controls for Scratch on tablets.
The gap between a functional prototype and a polished game is almost entirely determined by how far you want to push the iteration — and what your own comfort level with Scratch's event-based scripting model looks like at the moment you sit down to build it.