Scratch lesson 14 of 20 · Advanced · About 45–55 minutes
Build a trail wider than the Scratch Stage. Keep the explorer in view, move three landmarks past the camera and stop neatly at both ends of the map.
What you’ll make An explorable 960-unit world with one camera, a keyboard-controlled explorer and landmarks that appear as you travel.
Get ready
Open the Scratch editor (opens in a new tab) and start a new project.
- Keep the default sprite or paint a small explorer. Rename it Explorer. Aim for a costume no wider than about 40 units at its chosen size.
- Paint a flat, pale ground stripe across the Stage. A plain Stage works too. Avoid fixed scenery in the backdrop because it will stay in place.
- For all sprites, make two variables called Player World X and Camera X. Show their monitors at first so you can watch the numbers.
- Make a new broadcast message named Render by choosing New message in a broadcast block. You will use the same message in several scripts.
To keep your project, choose File → Save to your computer in Scratch.

Build it in Scratch
Choose the sprite named above each stack. The colours help you find the block categories. Indented rows sit inside the block above. Follow the end marker to see where each loop or condition closes.
1. Give the player a position on the map
A normal Scratch Stage is 480 units wide. This trail is 960 units wide, so keep the player's map position in Player World X. The left and right arrows change that number by 5 each time through the loop. Their effects cancel if both are held. The range 32–928 leaves room for the explorer's costume at either end. Start by making the Stage script below. Leave the two custom-block calls out until you create the blocks in the next two steps.
when green flag clickedset [Player World X] to (40)foreverif <key [left arrow] pressed?> thenchange [Player World X] by (-5)if <key [right arrow] pressed?> thenchange [Player World X] by (5)keep player on trailfollow playerbroadcast [Render] and waitwait (0.02) seconds2. Stop the player at the ends
Select the Stage, open My Blocks and choose Make a Block. Name this one keep player on trail. Put the two checks under its definition. If the position overshoots, the block sets it back to the nearest permitted value. Add the new block inside the Stage loop after the arrow checks.
define keep player on trailif <(Player World X) < (32)> thenset [Player World X] to (32)if <(Player World X) > (928)> thenset [Player World X] to (928)3. Follow with a camera that stops at the edges
Make a second Stage block named follow player. The camera is the map position you want at the centre of the screen. Give it the player's map position, then limit it to 240–720. At 240, the screen covers the first 480 units of the trail. At 720, it covers the final 480. Add this call before broadcast [Render] and wait. The Stage now finishes one camera update before starting the next one.
define follow playerset [Camera X] to (Player World X)if <(Camera X) < (240)> thenset [Camera X] to (240)if <(Camera X) > (720)> thenset [Camera X] to (720)4. Convert map position to screen position
Select Explorer. In its Render receiver, put a subtraction block into the x input of go to x: y:. The camera is always the middle of the visible area, so subtract it from the player position. Keep y at −70. Test the green flag. At the start, 40 minus 240 gives a screen x of −200. In the middle, the camera and player have the same map position, so the screen x is 0.
when I receive [Render]go to x: ((Player World X) - (Camera X)) y: (-70)show5. Reveal landmarks as the camera passes
Paint a small tree sprite and name it Tree. With Tree selected, create Screen X for this sprite only. Its map position is 180. The abs operator finds how far its screen position is from the centre, whichever side it falls on. If that distance is 220 or less, place it and show it. Otherwise hide it so Scratch cannot pin it visibly to the Stage edge. Duplicate Tree twice, draw a new costume on each duplicate and change the fixed map position in each copy to 470 and 805. The local Screen X lets the three receivers work at the same time without overwriting each other. Each receiver ends after deciding whether to show its sprite.
when I receive [Render]set [Screen X] to ((180) - (Camera X))if <([abs] of (Screen X)) < (221)> thengo to x: (Screen X) y: (-50)showelsehideTest your project
- Click the green flag. Check that the monitors read Player World X = 40 and Camera X = 240. Explorer should be near the left edge.
- Hold Right until both monitors match. Explorer should stay in the middle while scenery moves left. At the far end, check for Player World X = 928 and Camera X = 720.
- Walk back left. Each landmark should reappear from the direction you expect, then disappear away from the edge. Click the green flag again to reset the whole trail.
If something goes wrong
- A landmark seems stuck to the edge.
- Only run go to x: y: inside the visible branch. Check that the other branch hides the sprite.
- Only one landmark moves correctly.
- Check that Screen X is local to each landmark and that each copy uses a different fixed map position.
- The world takes one step then freezes.
- Check each Render receiver for a forever block. The Stage waits for every receiver to finish before its next frame.
Make it your own
- Add a signpost at map x = 620 and make it speak when Explorer stands nearby.
- Try a 1,200-unit trail. Work out the new right-hand camera limit by subtracting half the Stage width from the trail length.
What you’ve learned You can keep world coordinates separate from what the player sees. A clamped camera and short render messages let the same screen show a much bigger map.