Fox Studios logo Fox StudiosGame projects, devlogs and Scratch builds
Projects

How We Built a Match Three Puzzle Game in Scratch

We shipped a match three puzzle in Scratch in nine days, and the first six of those days were spent building the wrong thing.

A Scratch editor window showing an eight by eight grid of colored gems beside a script using a board list

We shipped a match three puzzle in Scratch in nine days, and the first six of those days were spent building the wrong thing. I had 64 tile clones each checking whether they were touching another clone of the same color, which felt like the obvious way to do it, and it worked perfectly until the board got full. Then a single swap took about four seconds to resolve, clones started vanishing for no reason I could explain, and one tester sent me a screen recording of a column of gems hovering in the air.

The fix was to stop treating the tiles as the game. Match three looks like a game about sprites touching each other and it is actually a game about a list of 64 numbers. Once the board lived in a list and the clones became dumb things that drew what the list said, the whole project got smaller, faster and much easier to explain in a feedback thread. Here is how we built it, with the parts that cost us days.

The board is a list, not a pile of sprites

Make one list called board with 64 items, each holding a number from 1 to 6 for the gem color. Position is implied by the index, which is the whole trick. Item 1 is the top left cell, item 8 is the top right, item 9 starts the second row.

Two small custom blocks do all the translation. To get the column from an index, use index minus 8 times the floor of the quantity index minus 1 divided by 8, and clamp it. To get the row, use the floor of that same quantity plus 1. Scratch has no floor block, so build one as a custom block using the round and the subtraction blocks, and test it on indices 1, 8, 9 and 64 before you trust it. We did not, and spent an afternoon debugging a board that was shifted one cell left on every second row.

Screen position comes from row and column: x equals negative 140 plus 40 times the column minus 1, y equals 140 minus 40 times the row minus 1. Forty pixels per cell on a 480 by 360 stage leaves room for a score panel on the right, which matters more than it sounds when you add a move counter later.

The clones then do nothing clever. Each clone owns a variable holding its index, and on every redraw it goes to the x and y for that index and switches costume to the color in the list. No touching checks anywhere in the project.

What the two approaches actually cost

I kept both versions, so these numbers are measured on the same laptop, a five year old machine with an integrated graphics chip, playing on the Scratch site rather than offline.

MeasureClones checking collisionsBoard stored in a list
Blocks in the project310188
Time to resolve one swap3.9 seconds0.18 seconds
Sprites and clones at once64 clones, all running scripts64 clones, drawing only
Bugs open after first test round112
Can you cascade matchesNot reliablyYes, with a repeat until loop
Days to build6 and abandoned3

The 0.18 second figure includes drawing, and it is comfortably below the 0.25 seconds where a swap stops feeling instant. The slow version failed for a specific reason worth naming: Scratch runs clone scripts one after another inside a frame, so 64 clones each doing their own comparisons means the work piles up while the screen waits.

Matching, gravity and the refill

Match detection is two passes over the list. Walk each row left to right counting how many cells in a row share a color, and when the run reaches 3 or more, add those indices to a list called matched. Then walk each column top to bottom and do the same. Duplicates in matched are harmless, since the next step only cares whether an index appears at all.

Clearing is a loop that sets every index in matched to 0, where 0 means empty. Gravity then runs bottom up: for each column, read the non zero values from the bottom, write them back to the bottom of that column, and fill the rest with 0. Refill replaces every remaining 0 with a random color from 1 to 6.

Wrap the whole sequence in a repeat until block that stops when matched comes back empty, and you have cascades for free. That was the moment the project started feeling like a real game instead of a demo, and it took fourteen blocks.

The piece nobody mentions is the starting board. A random fill gives you a board that already contains matches roughly four times in five, which means the game clears itself before the player touches it. Generate the board, run match detection, and if matched is not empty, reroll the matched cells only. Repeat until clean. Ours needs about three passes on average and has never needed more than nine.

The tutorial advice I would argue with

Most Scratch match three tutorials start by telling you to make the swap animation smooth: glide the two gems past each other over 0.3 seconds, then check for a match, then glide them back if there is none.

Build that last. We built it third and it hid two real bugs for days, because an animation that takes 0.3 seconds also swallows the window where the board is in an inconsistent state, so the broken state never appeared on screen long enough for me to see it. When I stripped the glide out and made swaps instant, both bugs showed up in the first two minutes of play.

The related advice I disagree with more strongly is to validate a swap before performing it, by simulating the result in a second list. It is correct and it is twice the code. Just do the swap in the board list, run match detection, and if matched is empty, swap the two items back. The player never sees it, it is seven blocks, and it handles the awkward cases a simulation gets wrong.

Where I was wrong in the other direction: I skipped the illegal move hint for too long. Twenty two testers played the first public build and nine of them got stuck staring at a board, and six of those nine quit rather than ask. A slow pulse on one valid pair after eight seconds of no input fixed it, and it is the single change that moved median session length from 2 minutes 40 to 6 minutes 10.

What we would do differently

Keep the score simple at first. We shipped with 10 points per gem and a 1.5 multiplier per cascade step, and nobody noticed the multiplier until we put the cascade count on screen in large text. Feedback is the mechanic, not the arithmetic, which is the same lesson from why tiny UI polish changes how players judge your game.

Use one sprite with 64 clones, not 64 sprites. If you are coming from a project like our snake game built with clones, that habit is already in your hands, and it keeps the block count where we ended up rather than where we started.

And start the timer and the move counter on day one, even as plain variables with no styling. A puzzle with no limit tests differently from a puzzle with 30 moves, and we learned that late enough to rebalance twice. The grid and loop structure here is close to what we used in our Scratch tower defense build, so if you have made that, most of this will feel familiar.

FAQ

How long does a match three game take to build in Scratch?

Three to four days of evening work once you keep the board in a list. Expect double that if you start with clones checking what they touch, because you will probably rewrite it.

Why do my gems overlap or line up wrong?

Almost always the row and column arithmetic. Test your index conversion on cells 1, 8, 9 and 64 by hand before you build anything on top of it.

How do I stop matches appearing on the starting board?

Fill the board randomly, run your match detection, reroll only the matched cells, and loop until detection comes back empty. It costs a few frames at startup and nothing afterwards.

Does this work inside the Scratch clone limit?

Yes. An 8 by 8 board uses 64 clones against a limit of 300, so you have room for particle effects later. Keep the clones free of scripts that run every frame and performance stays fine.

DF
Diego Fenn

Diego covers finished builds and the community around them, and runs the feedback threads that shape what the studio makes next.

More posts by Diego

More in Projects

01doorganico 084goad 3hot8 4465456 after5internprogram ahandfulofblessings ahmadpc ahomcybersecurity allodialresources annodex antiquesandperiodcollectibles aotc asianworldkashmir beedlectrics bloggertemplatefree bluefeatheragency bodyweightsolution campaign08blog carfixadvisor catstreetcollective cbstvsports cnfanspurchasing committeeof500yearsofdignityandresistance covertopsdjs cs-kaiyuangame cuestacomunicaciontotal cxoutlet dancebetgame deskgearhub destinyvillastay detectmagazine di33 diamondsteelbuildings donmo dyanadropship emarsysfinance emimattl escapechan eskitarih evautoplay everythingweddings-orlando farmzone feedviewerapp gamevui123 gleasongrade greetingsday hacklabasu haskell iw-kaiyun jagoanproperti jilidskripsi joltbusinessfinance juegodepokergratis juegospucca kaeru-festival latestmehndidesigns lestanzediottaviano litemagazines localcommunityhero lustrsazan mariashebets menswheels newwebstechs1 nikkit ootheday oxigenvpn plurfitness prefetial probudgetcarpetcleaning psychicmrsmartin pyaten qvantor rejoignezlogis rexzbot riselayouts ruchin rwxqsgd5 sakaltime shibiaowang shop-bot skrtips spotlesshaven strcoding tetapatrium topselller uneplanteartificielle vipertechcr webtech1223411 wo-kygaming yamaha-mekar yeknava yoybuysheets zenunwa yamaha-mekar jilidskripsi ankertoto ankertoto ankertoto