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:
- 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
. - On the ball sprite, find the forever block with the move (10) steps and if on edge, bounce blocks.
- Replace the when flag clicked block with the when I receive block. Select the play message.
- 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...