Scratch exercise 95

Scrolling terrain

In this tutorial you will create scrolling terrain (backgrounds) that a ball can roll along. The ball will cross gaps by jumping them.


Complete these steps ..


1. Create a new game (From the top menu choose File>New).


2. Delete the cat sprite.


3. Select the stage, click the "backgrounds" tab and edit/paint the stage sky blue.


4. Now click the "scripts" tab and add these scripts ..


5. Create this variable ..

The value in this "scroll x" variable will be controlled with the right and left arrow keys, and will be used to move the terrains across the stage. We don't need to see this variable on the stage so you can hide it if you like.


6. Download, save and then add ("choose sprite from file" button) these 8 sprites to your game ..


7. Save your game. Name it "Scrolling terrain".


8. Next we will make the terrain sprites scroll.

Add these scripts to "terrain 0". This terrain will not move but provide a static background to cover any gaps or glitching as the other terrains scroll across the stage ..

Note that the terrain is positioned near the bottom of the stage at y:-170.


9. Select "terrain 1" and add this script ..

Look at the script carefully and note the following ..


10. Copy the scripts form "terrain 1" to "terrain 2" and change the "set x to" multiplier from * 1 to * 2 ..

"terrain 2" will follow "terrain 1" in the scroll.


11. Do the same for the remaining terrain sprites, ensuring each time that you match the terrain number to its "set x to" multiplier, so for example, 'terrain 5" will have a multiplier of 480 * 5.


13. Re-save your game using File>Save.


14. Select the "ball" sprite and add these scripts ..

Note that ..

Press the "B" key and test the game.


15. Re-save your game using File>Save.

Well done, you're done! Can you develop this exercise into a complete game? How about adding more terrains?