🐦 Gravity + tap to flap Built block by block in Scratch
Programming
Programming · Scratch

How to Make Flappy Bird in Scratch: A Step-by-Step Guide for Kids

Build the world's most famous mobile game in about 45 minutes — no downloads, no typing, just colourful blocks.

Flappy Bird took the world by storm with one button and one rule: don't hit the pipes. In this tutorial you'll build your own version in Scratch — with gravity, flapping, moving pipes, and a score counter — using skills straight from our free Scratch for Kids course.

What You'll Build (and What You'll Learn)

Your finished game will have a bird that falls with gravity, flaps up when you press space, pipes that slide across the screen with random gaps, and a score that counts every pipe you pass. Hit a pipe or the ground — game over.

Flappy Bird is a genuinely useful project to build, not just a fun one, because it's the smallest game that still contains every core mechanic a bigger game needs: a physics-like variable that changes every frame, player input that fights against that physics, objects that spawn and clean themselves up, and a rule for what counts as "losing". Once these four ideas click, you can build platformers, shooters, and endless runners using the exact same building blocks.

📌 Before you start

New to Scratch? Do Lesson 1 — Meet Scratch first (15 minutes). If you've never used variables, peek at Lesson 9 — the Catch Game where we explain them with pictures.

Mechanic 1
Gravity
One variable, shrinking every frame, drives the fall.
Mechanic 2
Flap
Space key resets velocity to a positive burst.
Mechanic 3
Clones
One pipe sprite spawns infinite obstacles.
Mechanic 4
Collision
Touching blocks trigger game over and scoring.

Step 1 — Set Up Your Sprites

Before any code goes down, the stage needs its actors. This step takes about five minutes but sets the foundation for everything after it — get the sprite names right now and every script later on is easier to read and debug.

1

Open a new project

Go to scratch.mit.edu → Create. Delete the cat (right-click → delete). Add a flying sprite — "Parrot" works great, or draw your own bird.

2

Add a pipe sprite

Click the paintbrush to draw a sprite: one long green rectangle at the top and one at the bottom, with a gap in the middle. Name it Pipe.

3

Pick a backdrop

"Blue Sky" from the backdrop library is the classic look.

4

Make two variables

In the Variables category, make velocity (how fast the bird falls or rises) and score.

Naming matters more than it seems. If you call your bird sprite "Sprite1" you'll spend the rest of the tutorial second-guessing which script belongs where — rename it Bird right away by clicking its thumbnail in the sprite panel and editing the name field.

Step 2 — Give the Bird Gravity

This is the heart of the game, and it's only a few blocks. On the Bird sprite:

when green flag clicked
go to x: -100  y: 0
set velocity to 0
forever
   change velocity by -1     ← gravity pulls down a little more each frame
   change y by velocity      ← move by how fast we're falling

Press the green flag: your bird drops like a stone. That's gravity working! Every loop, velocity gets more negative, so the bird falls faster and faster — exactly like the gravity we build in Lesson 13.

The Numbers Behind the Fall (a Worked Example)

It helps to see exactly what the loop is doing frame by frame, rather than just taking it on faith. Say the bird just flapped, setting velocity to 10. Here's what happens over the next six frames, calculated directly from the two blocks in the script above:

Framevelocity (after -1)y position (after +velocity)
199
2817
3724
4630
5535
6439

Notice the bird climbs less each frame, even though it's still moving up — that's why the arc curves instead of forming a sharp triangle. Eventually velocity crosses zero and turns negative, and the exact same two blocks now pull the bird back down. One tiny piece of arithmetic, repeated automatically, produces motion that looks like real physics.

Step 3 — Make It Flap

Add a second script to the Bird:

when space key pressed
set velocity to 10      ← a burst of upward speed
start sound [Chirp]
💡 Why this feels right

Setting velocity to 10 (instead of just moving up) means gravity immediately starts eating the boost — so the bird arcs beautifully instead of teleporting. Small numbers = heavy bird, big numbers = floaty bird. Try 8, 10 and 13 and pick your favourite!

Why Forever Loops Are the Heartbeat of Every Game

It's worth pausing here to understand why the gravity script works, because the same shape — a forever block running dozens of times a second — sits underneath practically every video game ever made, from Flappy Bird to the biggest console releases. Each pass through the loop is called a frame, or a "tick": the game checks input, updates positions, checks for collisions, and redraws the screen, then does it all again immediately.

Check input Update velocity, position Check collisions Redraw …then it all happens again, dozens of times per second
This exact cycle — input, update, check, draw, repeat — is what "forever" means in every game engine, not just Scratch

Scratch runs its forever loops roughly 30 times a second by default. That's fast enough that a bird falling one pixel per tick looks like smooth motion to your eye — the same illusion that makes a flip-book or a film reel look alive.

Step 4 — Endless Pipes with Clones

You only need one Pipe sprite. Clones do the rest (this is the same trick from our Balloon Pop lesson). On the Pipe sprite:

when green flag clicked
hide
set score to 0
forever
   create clone of [myself]
   wait 2 seconds

when I start as a clone
go to x: 240  y: (pick random -60 to 60)   ← random gap height
show
repeat until x position < -235
   change x by -4                          ← slide left
delete this clone

Every 2 seconds a new pipe is born on the right edge at a random height, slides across the stage, and deletes itself off the left edge. Endless pipes, three blocks of memory.

Clones vs. Making New Sprites

A common early mistake is duplicating the Pipe sprite by hand in the sprite panel to get more pipes. It works for exactly one screen, then falls apart. Here's why clones are the right tool for this job:

Duplicate spritesClones
How many you can makeA fixed number, set by handUnlimited, created while the game runs
Code you have to write onceOnce per duplicate spriteOnce, ever — every clone reuses it
Memory when off-screenStays in memory even off-stageDeletes itself and frees memory
Good forA small, fixed cast of charactersBullets, pipes, enemies, particles — anything repeating

Step 5 — Game Over and Scoring

This is where the game gets rules. Right now the bird can fall forever and pipes can pass straight through it — nothing actually ends the game or rewards the player for surviving. Two small checks fix both problems at once. Back on the Bird sprite, add these checks inside the forever loop (after change y by velocity):

if touching [Pipe] ? then
   broadcast [game over]
   stop [all]

if y position < -170 then      ← hit the ground
   broadcast [game over]
   stop [all]

For scoring, add to the Pipe clone script, just before delete this clone:

change score by 1
start sound [Coin]
💡 Why "broadcast" instead of a variable

Broadcasting a message like game over lets every sprite react independently — the Bird can stop moving, the Pipes can freeze in place, and a "Game Over" text sprite can appear, all triggered by one signal instead of you wiring separate checks into every single sprite.

⚠️ Common mistake

If your bird dies instantly, your pipe costume probably fills the whole canvas — Scratch detects touching against the drawn pixels. Make sure the gap in your pipe drawing is really empty (transparent), not white.

Troubleshooting: Common Bugs and Fixes

Every Scratch builder hits the same handful of snags on this project. Here's the fast diagnosis for each one, before you spend twenty minutes staring at blocks that look correct.

SymptomLikely causeFix
Bird falls but never flapsThe flap script is on the wrong sprite, or the key isn't set to "space"Check the flap script is on the Bird sprite and the hat block reads space
Bird dies the instant you press playPipe costume has no transparent gapRedraw the gap with the eraser tool, not white paint
No pipes ever appearThe clone script never ran, or "when green flag clicked" is missingConfirm the Pipe sprite has its own green-flag hat block
Score doesn't increaseThe change score by 1 block sits outside the clone scriptMove it inside when I start as a clone, before delete
Game restarts oddly on green flagOld clones from the last run weren't clearedAdd delete this clone as a safeguard and avoid stray clone-creation loops
Bird flies off the top of the screenVelocity keeps adding without a capAdd an if velocity > 10 then set velocity to 10 check

Step 6 — Make It Yours

The base game is complete and playable at this point — everything below is optional polish. Pick two or three, not all six at once, or you'll lose the plot debugging six new features simultaneously.

Upgrade 1
Speed up over time
Use a speed variable instead of -4 and change it by -0.2 every 10 points, so the game gets harder the longer you survive.
Upgrade 2
Animate the flap
Switch costume when space is pressed, switch back 0.2 seconds later, for a wing-flap effect instead of a static bird.
Upgrade 3
Track a high score
Add a second variable that only updates when score > high score, so players have something to beat next run.
Upgrade 4
Sounds and music
Our Sounds lesson shows how to loop background music properly without it restarting every frame.
Upgrade 5
Parallax background
Add a second, slower-scrolling backdrop layer behind the pipes for a sense of depth — the same trick used in most side-scrollers.
Upgrade 6
Give the bird lives
Instead of instant game over, subtract one life per collision and add 1 second of "invincibility" so a single graze isn't an instant loss.

FAQ

Do I need to install anything to follow this tutorial?

No. Scratch runs entirely in your browser at scratch.mit.edu — no downloads, no account required to build and test the game, though you'll want a free account to save your project.

My pipes overlap the bird's starting position — what's wrong?

Check the pipe's starting x position matches the stage width you're using (240 for the default 480-wide stage) and that the bird's starting x (-100 in this tutorial) leaves enough runway before the first pipe arrives.

Can I make the bird a different character, like a rocket or a fish?

Yes — the gravity and flap scripts don't care what the sprite looks like. Swap the costume for any sprite from the library or draw your own, and consider renaming the pipes to match your new theme (asteroids for a rocket, for example).

Why does my score reset to a huge number instead of 0?

This usually means set score to 0 is missing from the green-flag script, so the variable keeps whatever value it held from a previous test run. Add it back at the very start of the Pipe sprite's script.

How do I make the game harder without it feeling unfair?

Increase difficulty gradually rather than all at once — shrink the pipe gap or speed up the pipes by a small amount every few points, instead of a single jump in difficulty right after the game starts. Players notice a game that "cheats" far more than one that ramps up smoothly.

Before You Call It Done — Test These

It's tempting to stop as soon as the game runs once without crashing. A quick pass through this checklist catches the bugs that only show up after a few minutes of real play, not the first ten seconds.

· · ·

You Just Built a Real Game

Gravity, clones, collisions, score — these four patterns power thousands of games. Change the bird to a rocket and pipes to asteroids and you've made a totally new game with the same code. That's the real skill you've practiced here: recognising that "different game" often just means "different costume on the same logic".

The Essential Points

  • Gravity = a velocity variable that shrinks every frame and moves the sprite
  • Flapping = setting velocity to a positive burst, then letting gravity win
  • One pipe sprite + clones = infinite obstacles with random gaps, and clones clean up after themselves
  • Touching blocks + broadcast = clean game-over logic
  • Every game is built from the same loop: check input, update, check collisions, redraw, repeat
  • Ready for more? Build the Space Shooter next — it levels up every trick you used here
IA
Irfana Aslam
Founder · AI Researcher · Full-Stack Developer, BitWithBite
Advancing science through Artificial Intelligence, Computer Vision, and impactful technology solutions. Irfana built BitWithBite from scratch to make world-class tech education accessible to every learner worldwide.