Game Development Reference
In-Depth Information
That concludes the base sprite script. Next we will create a clone script. This will control how
the clones will move, just like in the previous examples.
1. We first need to define a variable called position only for this sprite.
This variable will store a virtual x posiion value. We use this method to
allow a value to go beyond the borders of the stage.
2. We will start a new script by using the when I start as a clone block.
3. We will set the posiion to 300 in the set <posiion> to() block. This is beyond the
right border of the stage.
4. Then, enable the show block to show the cloned sprite.
5. We will move the clone inside a repeat unil () loop.
6. We irst change the posiion variable by scrollingSpeed * speedMuliplier .
7. Then, we set x to posiion using the set x to () block.
8. To ill the condiion slot, we check when the posiion is less than -300 by entering
-300 in the posiion < () block.
9. When that happens, we can delete this clone by using the delete this clone block
as it is beyond the left edge of the stage.
Our first scrolling sprite is now finished. Test the script and we will see that the rocks and
seaweed move a lot faster than the background image.
To make full use of the effect, we need a few more layers of objects though. We will create a
few more background objects moving at different speeds:
Let's copy the Rocks sprite twice.
For the first copy, we edit the script in a few places.
Search WWH ::

Custom Search