Scroll Down
With the help of an existing project, we show you how to program scrolling sprites in a series or in a continuous loop.
With the help of an existing project, we show you how to program scrolling sprites in a series or in a continuous loop.
Scrolling sprites is a sought-after skill for a Scratch programmer, and it sounds like a big challenge. Creating the effect is not as complicated as it may seem, however. In this article, I will introduce two methods to make sprites scroll – this is sometimes called a "scroller" project in Scratch. Scrolling is also a fundamental concept in creating a platform game, which is one reason Scratchers want to learn how to do it.
For this project, I won't go through the entire process of drawing multiple frames with platforms in the Paint Editor. Instead, I'm going to remix the FishChomp game that comes bundled with the example projects in your Raspberry Pi version of Scratch.
To find the FishChomp project, select File | Open and then from the Open Project dialog box, click Examples and browse to the Games folder.
The original game play for FishChomp is to steer the fish around the sea using the mouse pointer with the goal of trying to eat as many goldfish as possible. All the action is confined to the boundaries of the Scratch stage, and the sprites bounce off the edges.
I find it nearly impossible to resist the urge to change up the game considerably when I remix something, and this project is no different. If you download the project files [1], you'll notice some changes. For example, the fish sprite is controlled with the left, right, up, and down arrows instead of the mouse pointer. I added a score-keeping metric in which the fish gains a point for each goldfish consumed and loses a point each time it touches the sea floor. There's more work to be done, but you get the idea.
I chose to demo a scrolling project as a way to put my new Rasp Pi 2 (RPi2B) [2] to the test. Scrolling is still a bit slow compared with a non-Pi environment, and as I go through the examples, I'll point out the values that can help make the scrolling smoother. The performance of the scrolling demos is definitely better (faster) with the RPi2B.
A noticeable benefit of the RPi2B with the 2015-02-16-raspbian-wheezy image is that the Scratch editor is quick and responsive. The Scratch version included with the image is Scratch 1.4 as of January 14, 2015 [3]. It's clear the active Scratch development on Rasp Pi is paying off.
Perhaps one of the trickiest parts of scrolling in Scratch is that you're actually using sprites, not backgrounds. This is true even when you want the scrolling effect to appear as a background. You need to use sprites to create the scrolling effect for a couple of reasons. In the Scratch 1.4 version that ships with the Rasp Pi, backgrounds and sprites do not sense one another. Also, the stage, which contains the backgrounds, does not have any motion blocks, and the set x to ()
block is critical.
My scrolling examples will scroll sprites that are exactly the width and height of the Scratch stage (480x360 pixels); however, you can scroll sprites that are smaller than the stage. You only need to know the size of the scrollable area and then create sprites to that size.
Pages: 4
Price $15.99
(incl. VAT)