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

How We Built a Scrolling Platformer in Scratch

Every Scratch platformer we made before this one fit on a single 480 by 360 stage, and every playtester asked the same thing: why does the level end at the edge of the screen?

Laptop on a desk showing a colorful side scrolling game level with a small character jumping between platforms

Every Scratch platformer we made before this one fit on a single 480 by 360 stage, and every playtester asked the same thing: why does the level end at the edge of the screen? Building a scrolling platformer in Scratch fixes that, but the moment you move the world instead of the player, collisions, enemies and jumps all start to misbehave.

This is the devlog of our two week build, a small game called Lantern Hop. It covers the camera trick that makes scrolling work, the bugs that cost us the most time, and what we would do differently on the next one.

The core idea behind a scrolling platformer in Scratch

Scratch has no camera. The stage is fixed, and sprites cannot be placed far outside it. So the trick is to keep two kinds of position for everything in the level:

  • World position, stored in variables, which is where something really is in the level.
  • Screen position, which is the world position minus a global variable we called scroll x.

The player sprite stays near the middle of the screen. When the player walks right, scroll x goes up, and every other sprite subtracts scroll x from its world position before drawing itself. Ground, coins and enemies slide left, and the illusion holds.

Our level was 3,840 pixels wide, which is eight screens. We drew it as eight costumes of one "ground" sprite, each 480 pixels wide, and used two clones that leapfrog each other. When a tile scrolls fully off the left side, it switches to the costume eight tiles ahead and jumps to the right edge.

How we built it, week by week

Week one: movement and the camera

We started with movement on a flat floor before any scrolling. Horizontal speed uses acceleration and friction: add 1.2 to speed x when an arrow is held, multiply speed x by 0.8 every frame, and cap it at 8. That gives a little slide without feeling icy.

Then came scrolling. We set scroll x equal to the player's world x every frame. That one line made the player stay locked in the center. It felt stiff, so we added easing: each frame, scroll x changes by one fifth of the gap between where it is and where it wants to be. The camera now trails slightly behind, which looks far more natural.

We also clamped scroll x between 0 and 3,360 so the camera never shows empty space past the ends of the level.

Week two: collisions, enemies and polish

Collision is where most Scratch platformers break, and ours was no exception. We used a separate invisible hitbox costume on the player, a plain rectangle 20 pixels wide and 32 tall, so the animated costume would not snag on edges. Each frame, the script moves the player by speed x, checks "touching ground", and if it is touching, steps back one pixel at a time until it is free. Then it does the same for speed y.

Enemies got their own world x variable and a patrol range. Coins were clones with a world x set when the level loaded. We kept the clone count under 60, because past roughly 100 active clones our test laptops started dropping frames.

The last three days went to a health bar, a checkpoint flag halfway through, and sound.

The bugs that cost us the most time

Some of these were obvious in hindsight. All of them cost at least an evening.

  1. Sprites refusing to go off screen. Scratch keeps a sprite partly visible at the edge even if you tell it to go to x 600. Our coins piled up on the right edge like a fence. The fix was to hide any sprite whose screen x was beyond 260 or below minus 260, and show it again when it came back.
  2. Running the camera before the player moved. Our scripts ran in a random order, so sometimes coins drew with last frame's scroll x and jittered. We switched to one main loop that broadcasts "move", then "camera", then "draw", and waits for each.
  3. Falling through the floor at high speed. When speed y hit minus 20, the player skipped through thin platforms. Capping fall speed at minus 12 fixed it without changing how jumps felt.
  4. Turbo mode hiding problems. Our lead tested in turbo mode, and everything looked smooth. On a school Chromebook it ran at 20 frames a second. Test on the slowest machine your players will use.

Why we stopped chasing pixel perfect collisions

A lot of Scratch tutorials push you toward pixel perfect collision with the full character costume and a careful slope system. We tried that first and spent four days on it. It felt technically impressive and played worse.

Players do not notice whether a character's elbow clips a ledge. They notice when they get stuck on a corner they clearly cleared. A plain rectangle hitbox a little smaller than the visible art gave us more forgiving jumps and fewer stuck states. We dropped slopes entirely and used short steps of 8 pixels, which the step back loop handles automatically.

That lines up with something we keep relearning, and wrote about in why your first game should be tiny: the simplest system that feels good beats the clever one you cannot finish.

What we would change next time

Lantern Hop shipped with eight screens, 42 coins, five enemy types and one checkpoint. Playtesters finished it in about four minutes on average, which was shorter than we wanted but the right size for a two week build.

  • Use a list for level data. We placed coins and enemies by hand in scripts. Storing their positions in a list would make new levels a matter of editing numbers.
  • Add vertical scrolling early. We only scroll horizontally. Adding a scroll y variable later means touching every sprite again.
  • Build the pause menu first. It was the last thing added and the hardest to retrofit into the main loop.

If you want a smaller warm up before trying this, our endless runner built in Scratch over one weekend uses a simpler version of the same scrolling trick with only one direction of movement.

Frequently asked questions

How do you make the screen scroll in Scratch?

Store a scroll x variable and give every level sprite its own world x. Each frame, set each sprite's x position to its world x minus scroll x. The player stays near the center while the world slides past.

Why does my Scratch platformer character get stuck in walls?

Usually the costume used for collisions has uneven edges or changes shape during animation. Use a separate rectangle hitbox costume and move horizontally and vertically in separate steps. After each step, back the player out one pixel at a time until they are no longer touching the wall.

How many clones can a Scratch game handle?

Scratch caps clones at 300, but performance usually drops long before that on older devices. Keeping active clones under about 100 is a safe target for a platformer. Delete clones that are far off screen and recreate them when needed.

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