Scratch Cookbook
上QQ阅读APP看书,第一时间看更新

Adding words to a sprite

One of the first things we need to know to tell a story using Scratch is to display words on the screen to convey the story. For this recipe, we'll need to use some of the concepts we learned in the previous chapter.

Getting ready

Start off by importing a new sprite (unless you like the default) as well as a background you like. Also, start thinking about a story you want to tell—or you can just follow what we do here!

There are two blocks that we are going to use to accomplish all of this, one of which we used already in the previous chapter. This family of blocks are the say and think blocks:

Recall that the first one in this list is the block we used in the previous chapter.

Tip

So what's the difference between all of these blocks?

Two of these blocks help with timing. These are the first and third in the picture that include a time condition. These are the ones we will focus on because we generally want to control how long the words are displayed on the screen.

The story we are going to make here is going to be told by Monkey Mike. We labeled our sprite this to make understanding the logic of the programming a bit easier.

Now we're ready to get building a story!

How to do it...

Follow these steps to get going:

  1. Drag over the block with the green flag that we used to start our programs in the previous chapter from the Events category. We'll start our story by clicking on the green flag on the stage.
    Note

    Still using the older version of Scratch (Scratch 1.4)? All of the blocks in the Events category can be found in the Control category. This new category was added with the new version of Scratch.

  2. Next, we're going to return to the Looks block category and drag over the think block, the first one including the timing.
  3. Enter Hmm…I guess I'll start telling a story. into the text block.
  4. Click on the green flag and test the program. You should see a thought bubble pop up as if your sprite is thinking. It should be similar to the following screenshot, depending of course on the background and sprite you chose:
    Tip

    You may wish to adjust the number of seconds for which the thought bubble appears. You do this by changing the number associated with the think block in the code. Enter the number of seconds it shows for how long you expect your viewer to need to read the text. The same rule applies for other texts being displayed.

  5. Now, we can drag in our next block—the say block—again including the timing element.
    Note

    You might be wondering what is the difference between the say and think blocks. Both accomplish similar goals. You can think of them as cartoons. The think block imitates the thoughts of the character while the say block suggests that the character is saying something. Note that neither makes the character make a noise.

  6. Enter the text in this block as Hi, my name is Monkey Mike. We can continue creating a basic story by adding more and more of these blocks to our code.
    Note

    If you want to end your story with the text remaining on the screen, just use the say or think block without the timing element. This will keep the text on the screen until the viewer either starts the program over or does something else to trigger it (we'll learn more about this option later).

How it works...

So far, this program is relatively simple. Our code so far is:

We can see this sequence of code starting off with the green flag being clicked. Following that, our sprite thinks about starting the story, and then he begins. Naturally, your program may vary depending on how much you've digressed from the story we are using here.

See also

  • For more information about timing your story, particularly with multiple sprites in the story, see the next recipe, Adjusting the timing