How to create a scrolling sprite project
Layering Sprites
The scripts in Figures 1 and 3 include a go back
()
layers
block. As the block implies, Scratch can layer sprites, which means one sprite could obscure the view of another sprite. In this case, you want to the scrolling sprites to represent a background, so you should send them back a sufficient number of layers to ensure they are behind all other sprites. By sending the scrolling sprites to the back, you ensure the goldfish
and hungry fish
sprites are always visible and in front of the scrolling sprites.
Wrapping It Up
As you explore the scrolling effects, some glitches may present itself. Specifically, when you move the fish to the left and the frames scroll in from the right, there is a small gap in the backgrounds. This glitch disappears when you play the game in presentation mode.
Also, in the example that scrolls a series of sprites, the frames overlapped and stayed visible on the right edge of the stage. I noticed this problem because my sprites' edges did not line up cleanly, which is a concern as you create sprites to scroll. The more the design flows seamlessly from one sprite to the next, the better.
Figure 4 shows how I fixed my overlapping sprites. If everything was working as expected, the sprite would not be visible when it scrolled to an x position of 480. However, in my example, the sprite stopped scrolling at an x position of 462. I know it's 462 because I used the x position monitor to observe the position of the sprites. That forms the basis of the revised script in Figure 4, which hides the sprite when its x position is greater than 461. Each frame would need the same x position evaluation. I only experienced the error when the sprites scrolled from left to right. If you experience problems scrolling the other way, you could implement a similar check.
Now you have everything you need to start your own platform game or project with scrolling sprites. Happy Scratchin'.
Infos
- Download project files: http://scratchguide.com
- Raspberry Pi 2: https://www.raspberrypi.org/raspberry-pi-2-on-sale/
- Scratch 1.4: https://scratch.mit.edu/scratch_1.4/
« Previous 1 2 3 Next »
Buy this article as PDF
Pages: 4
(incl. VAT)