- Learnt28 min · walk, then pull the world back; screen x and world x
- Basic24 min · the scroller
- Challenge 1–327 min · respawns, a crab, a checkpoint
- Extrabonus · a camera that looks ahead
Review — move the world 5 min
scroll xsays how far along the world the Stage is looking.- Everything sets
set x to ((my x) - (scroll x)). - Far-away sprites hide, or they wait at the edge of the Stage.
Quick-fire
Last lesson the arrow keys changed scroll x instead of Pico’s x. What goes wrong if you try that with Jump Quest’s Pico, which has walls?
Reveal the answer
The walls stop working. Pico’s walk block moves Pico, asks whether it hit green, and undoes the move. If Pico never moves, there is nothing to ask about. Today Pico goes back to walking for real — and the world catches up afterwards.
Today’s Topic 3 min
- Walk for real, then pull the world back
- Screen x and world x:
((scroll x) + (x position)) - Respawn points, enemies and checkpoints that live in the world
Learning outcome
By the end of this lesson you will be able to:
- Put a Jump Quest character into a scrolling level without rewriting its physics.
- Tell a screen position from a world position, and use the right one.
- Make a respawn, an enemy and a checkpoint work in a world bigger than the Stage.
Learnt — a camera that follows 28 min
1 · Walk for real, then pull the world back
Keep every block of Pico’s Jump Quest loop: walk, gravity, land, the jump. They move Pico across the Stage as they always did, and the walls and floors work because the world is standing still while they do. Then, at the very end of the tick, add one My Block:
define scroll the world
change [scroll x v] by (x position)
set x to (0)
if <(scroll x) < (0)> then
set x to (scroll x)
set [scroll x v] to (0)
end
if <(scroll x) > (1440)> then
set x to ((scroll x) - (1440))
set [scroll x v] to (1440)
end
broadcast [scroll v]
ifs are last lesson’s ends: there, the world stops and Pico keeps what is left.How to use this: Click the green flag and watch Pico cross all four screens of level 1 on its own.
2 · Two kinds of x
Pico’s x position is now nearly always 0, so it tells you nothing about where Pico is in the level. That is its screen x. Where Pico really is — its world x — is the scroll plus that:
set [world x v] to ((scroll x) + (x position))
How to use this: Click the green flag. Watch the scroll x and world x monitors while Pico walks and hops.
Basic — the scroller 24 min
Combine your road from last lesson with your Pico from Jump Quest.
Step 1 — a level worth scrolling
- Repaint the four Ground costumes as a level: gaps with water in them, steps 50 up, a crate. Name them
L1 screen 1toL1 screen 4. - Keep the ground and steps one green, and the water one blue, exactly as in Jump Quest.
- Change the costume
jointo(join [L1 screen ] (screen)).
Step 2 — bring Pico across
- Drag your Jump Quest Pico onto this project’s sprite list, or export and import it.
- Its
land,walkand hitbox come with it. Change nothing. - Delete last lesson’s road-walking Pico.
Step 3 — pull the world back
- Make the
scroll the worldblock from Learnt part 1. - Put it as the last block inside Pico’s forever loop.
- Start Pico at x −180 with
scroll xat 0.
Step 4 — water and the flag
- Touching the water: go to x −180, set
y velocityto 0, setscroll xto 0, and broadcast scroll. - Put the finish flag at world x 1600, placed the same way as the screens.
when flag clicked
go to x: (-180) y: (-104)
set [scroll x v] to (0)
set [y velocity v] to (0)
forever
if <key (right arrow v) pressed?> then
point in direction (90)
walk (4) :: custom
end
if <key (left arrow v) pressed?> then
point in direction (-90)
walk (-4) :: custom
end
change [y velocity v] by (-1)
change y by (y velocity)
land :: custom
if <<key (space v) pressed?> and <(on ground) = (1)>> then
set [y velocity v] to (12)
end
scroll the world :: custom
if <touching color [#2F80ED]?> then
go to x: (-180) y: (-104)
set [y velocity v] to (0)
set [scroll x v] to (0)
broadcast [scroll v]
end
if <touching (Flag v)?> then
say [Level complete!]
end
end
How to use this: Click the green flag. Arrows to walk, space to jump. Cross all four screens to the flag.
Pico walks through steps and crates.
scroll the world is before walk or land. Move it to the very end of the loop.
Pico drifts off towards the edge of the Stage.
The set x to (0) is missing, so the world scrolls but Pico is never put back in the middle.
The world goes the wrong way.
change [scroll x] by (x position) — plus, not minus. Pico right of middle means the world must slide left, which is a bigger scroll x.
After falling in the water, Pico reappears somewhere strange.
That is Challenge 1.
The respawn that forgot the camera
Fall into the first pit twice — once with a respawn that only moves Pico, once with one that resets scroll x too. Report Pico’s world x each time.
- Both respawns go to x −180.
- Only one sets
scroll xto 0. - Work out Pico’s world x after each.
How to use this: Click the green flag. Pico walks into the first pit twice and reports where it came back.
Teacher note
“Go to x −180” is a screen position: it only means “the start” while scroll x is 0. This is the lesson’s central idea turning up as a bug, and it is worth letting the class find it in their own scroller before showing them this.
A crab in the world
Add a crab that patrols a stretch of ground — in the world, not on the Stage.
- The crab keeps its own
my xand changes that to patrol. - It places itself with
set x to ((my x) - (scroll x)), and hides when it is off the Stage. - Try a second crab that just changes its x, and watch the difference.
How to use this: Click the green flag. Pico walks right; watch both crabs.
Teacher reveal — the patrol, in world coordinates
forever
repeat (20)
change [my x v] by (-2)
set x to ((my x) - (scroll x))
end
repeat (20)
change [my x v] by (2)
set x to ((my x) - (scroll x))
end
end
Cheese Maze’s patrol, with one change: the crab moves its my x, and works out its Stage x from that every step. Anything that lives in the world has to.
A checkpoint in the world
Put a checkpoint flag at world x 540. Once Pico has touched it, falling in the water brings Pico back there — the camera as well.
- A
respawn xvariable, −180 at the start, set to 540 by the checkpoint. - The water sets
scroll xtorespawn x, puts Pico at x 0, and pulls the world.
How to use this: Click the green flag. Pico reaches the checkpoint, then walks back into the pit behind it.
Teacher note
Notice the respawn is now one number, a world x, and the camera is worked out from it. That is the right way round: store where things are in the world, and let the Stage follow.
A camera that looks ahead
In most side-scrollers the hero is not in the middle: they are a little to the left, so you can see more of what is coming. Keep Pico at x −100 instead of 0.
- Change
scroll the worldso it aims Pico at −100. - The ends of the level still work.
- Play a level both ways and decide which is fairer.
How to use this: Click the green flag and watch where Pico sits on the Stage as it walks.
Teacher note
The best follow-up question: should the camera look ahead when Pico walks left, too? Answering it properly needs the direction Pico faces — and the pupils who get there have invented the camera most commercial platformers use.
Summary 5 min
- Pico walks for real, then the world is pulled back by the same amount.
scroll the worldgoes last in the tick, after every collision.- Screen x is where on the Stage; world x is
((scroll x) + (x position)). - Respawns, enemies and checkpoints are all world positions.
- Camera
- The part of the world the Stage is showing — here, set by
scroll x. - Screen x
- A position on the Stage, from −240 to 240.
- World x
- A position in the whole level.
- Respawn
- Coming back after a fall — which, in a scrolling game, moves the camera too.
Hand in
Save your scroller. Next lesson it gets a second level, with its own screens and its own sky.