Skip to main content

Stage 4: Auto-Scroll Motion

Stage 4: Auto-Scroll Motion

Course progressStage 4 of 10
~90 min
Your workspace

Keep your Scratch project tab open all week. Open in a new tab so you don’t leave the course.

Build

a spike that scrolls from right to left

Learn

how runner games fake forward movement

Ship

a moving obstacle loop

Teacher demo
  1. Keep Cube near the left side.
  2. Move Spike left by 6 inside a forever loop.
  3. When Spike reaches the left edge, send it back to the right.
  4. Show how changing the speed changes the difficulty immediately.

The big idea

The cube does not need to run across the whole stage. The level moves toward the cube, which creates the feeling of speed with simpler code.

New words
scrolling
moving the level pieces to create motion
loop point
the position where an object resets to repeat
speed
how many steps an object moves each frame
difficulty
how demanding the game feels to play
Before you start

Stage 3 should be done. Spike exists and Cube can crash into it.

Use the examples

Follow the target shapes shown here so your scripts match the lesson quickly.

Make your own

Draw a custom cube, spikes, portal, or backdrop in Scratch. Keep the same sprite names so the code still works.

Finished game target
Cube runnerSpike obstacle

The cube stays near the left side while the level scrolls toward it. Jump timing is the whole game.

Build it

  1. Click the Spike sprite.
  2. Put Spike on the right side at x: 260 y: -100 when the game starts.
  3. Add the scrolling loop below.
  4. Jump the cube as the spike reaches it.
  5. Tune the speed only after the reset works.

Spike scrolling loop

when green flag clicked
go to x: (260) y: (-100)
show
forever
if <(gameOn) = (1)> then
change x by (-6)
if <(x position) < (-260)> then
go to x: (260) y: (-100)
end
end
end

Understand it

Resetting the spike is the first version of a level loop. Later, clones will make that loop feel less predictable.

Try this

Learning beat

Try this

Three short experiments. Predict before you run, then test your guess.

Predict first
Change -6 to -12. Predict what happens to the jump timing.
Compare
Try resetting at x: 220 and x: 300. Which gives the player better warning?
Connect
Stage 5 uses clones. Why might one spike not be enough for a real level?

Test your stage

  • Spike starts on the right.
  • Spike moves left only while gameOn is 1.
  • Spike returns to the right after leaving the stage.
  • Cube can jump over the moving spike.

If it breaks

  • If Spike moves during crash, check the gameOn condition.
  • If Spike disappears forever, check the reset x-position and less-than comparison.
Coach notes

Keep students moving on the default path first. Custom assets are encouraged, but the required names and variables are not optional. If debugging takes more than a few minutes, compare the student's sprite names, variable names, and block order against the stage test list.