Game Development Reference
In-Depth Information
Engage thrusters
For the scrolling background, we will need two idenical images with slightly diferent scripts.
The easiest way to create this is to write one script first. Then, copy the image including the
script and make the necessary changes.
1. Start with a
when <green lag> clicked
block.
2. Define a variable called
speedMultiplier
. Remember that the buton to do this
is in the
Data
category. This variable should be for this sprite only.
3. Enter
0.5
in the
set <speedMuliplier> to ()
block.
4. Make the image go back 100 layers by entering
100
in the
go back () layers
block.
We just use a suitably high number so that the image is placed behind all other
sprites on the stage.
5. Then, we posiion the image to its staring point with the
go to x: () y: ()
block; enter
-240
and
0
respecively. So the center of the image is at the let edge of the stage.
6. We add a
forever
loop, which will contain the movement script.
7. First we need another variable called
scrollingSpeed
. This variable should be
for all sprites. We will use it as a base speed value.
8. At each step of the loop,
change x by ()
. The blank slot will take a value that sill has
to be determined.
9. Here we include a calculaion—
scrollingSpeed * speedMuliplier
. We use the
muliplier to slow down the background image compared to the scrolling speed
of the base. Remember we set it to
0.5
so the background will move at half of
the speed.
When the image has scrolled completely out of view, we have to reset it to the right of the
stage so that it can scroll in again. To do this, we check where the image is. Also, if it has
reached a certain limit, we move it to the right of the stage.
1. We place an
if () then
condiion check underneath the
change x by ()
block.
2. Inside the condiion, we check whether x posiion (from the Moion category)
is less than -460 by entering
-460
in the
x posiion < ()
block.