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.

Figure 4: Each scrolling sprite's script can be updated to hide the sprite to keep it from incorrectly overlapping the other sprites on the screen.

Now you have everything you need to start your own platform game or project with scrolling sprites. Happy Scratchin'.

The Author

Michael Badger wrote the Scratch 1.4 and 2.0 Beginner's Guide series from Packt Publishing. Learn more at http://scratchguide.com

Buy this article as PDF

Express-Checkout as PDF

Pages: 4

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content