Stage 4: Auto-Scroll Motion
Stage 4: Auto-Scroll Motion
Keep your Scratch project tab open all week. Open in a new tab so you don’t leave the course.
a spike that scrolls from right to left
how runner games fake forward movement
a moving obstacle loop
- Keep Cube near the left side.
- Move Spike left by 6 inside a forever loop.
- When Spike reaches the left edge, send it back to the right.
- 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.
- 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
Stage 3 should be done. Spike exists and Cube can crash into it.
Students may follow these examples or draw their own versions in Scratch. Keep the sprite names from the lesson.
Follow the target shapes shown here so your scripts match the lesson quickly.
Draw a custom cube, spikes, portal, or backdrop in Scratch. Keep the same sprite names so the code still works.
The cube stays near the left side while the level scrolls toward it. Jump timing is the whole game.
Build it
- Click the Spike sprite.
- Put Spike on the right side at x: 260 y: -100 when the game starts.
- Add the scrolling loop below.
- Jump the cube as the spike reaches it.
- 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
Try this
Three short experiments. Predict before you run, then test your guess.
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.
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.