Book Image

Scratch 2.0 Beginner's Guide: Second Edition

By : Michael Badger
Book Image

Scratch 2.0 Beginner's Guide: Second Edition

By: Michael Badger

Overview of this book

Table of Contents (18 chapters)
Scratch 2.0 Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – coordinating the ball play


Now that we have the rows of bricks built and we know all about custom blocks, it's time for an easier problem. In our script, the ball starts before the bricks are built. We can use broadcasts to coordinate the two events. The steps are as follows:

  1. With the brick sprite selected, add a broadcast block to the end of the stack that builds the rows of bricks. Give it a clear name, such as play.

  2. On the ball sprite, find the forever block with the move (10) steps and if on edge, bounce blocks.

  3. Replace the when flag clicked block with the when I receive block. Select the play message.

  4. Now, when you start the game, the ball should not start until after the bricks are all created. However, the ball remains visible on the screen. We must hide it by adding a hide block to the script that initializes the lives variable and sets the starting position and direction. Then, add a show block to the when I receive (play) block.

What just happened?

We don't want the...