Book Image

Scratch Cookbook

By : Brandon Milonovich
Book Image

Scratch Cookbook

By: Brandon Milonovich

Overview of this book

Scratch 2.0 is an easy to use programming language that allows you to animate stories and create interactive games. Scratch also gives you the capability of using programming to calculate complicated calculations for you. Scratch Cookbook will lead you through easy-to-follow recipes that give you everything you need to become a more advanced programmer. Scratch Cookbook will take you through the essential features of Scratch. You'll then work through simple recipes to gain an understanding of the more advanced features of Scratch. You will learn how to create animations using Scratch. Sensory board integration (getting input from the outside environment) will also be covered, along with using Scratch to solve complicated and tedious calculations for you. You'll also learn how to work through the exciting process of project remixing where you build on the work of others. Scratch Cookbook will give you everything you need to get started with building your own programs in Scratch that involve sounds, animations, and user interaction.
Table of Contents (17 chapters)
Scratch Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using mouse control


Alternatively, we could use the mouse to control the red bar and give the mouse the freedom to move all around the stage.

Here's how we could go about doing this.

Getting ready

To get started, we'll need to take our program from the end of the last recipe and eliminate the arrow key controls; this way we can focus on the mouse controls.

In the userBar sprite, delete all three scripts that we have. Now we're ready to go!

How to do it...

  1. Drag over a block to the script area for userBar.
  2. Insert a forever loop below the top hat block we just placed.

  3. Inside the forever loop, place a go to () block from the Motion category.

  4. Using the drop-down menu in the new block you just dragged over and select the mouse-pointer option.

Your code should look like the following set of blocks:

Now give playing your game a shot!

How it works...

The code for this recipe is much simpler than our last recipe. It starts when we have the green flag clicked, which initiates a forever loop. From there, the...