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

Getting the mouse position


There are many times where it may be useful to have the mouse position in the program. Perhaps you want an object to follow the mouse, perhaps you want something to happen based on the mouse position, such as a graphic effect.

Getting ready

In this recipe, we're going to create a program that makes our sprite change its graphic effects based on the mouse position.

Start off by creating a new file and importing a new sprite. In our case, we've imported Monkey1 with the white background.

How to do it...

We're going to apply two effects, one based on the mouse's horizontal direction, another based on the mouse's vertical direction. Follow along with these steps:

  1. Drag over a green flag block (from Events).

  2. Drag over a forever loop (from Control).

  3. Inside the forever loop, drop a set () effect to () block from the Looks category and make the effect that we work with whirl.

  4. Also into the forever loop, drop a set () effect to () block as well, this time make the effect color. We...