20
Introduction to Scratch Programming v1.4 (Second Ed) 1 – Basics of Animation and Movement Introduction to Scratch Programming (2 nd Edition) Page 1 of 20 © ZigZag Education, 2013 Lesson 1 – Basics of Animation and Movement What you will learn: what Scratch does and the basics of the Scratch interface how to create a simple movement program (called a script in programming language) how to make the sprite reverse direction how to make the movement go on forever (until you stop the program) how to combine this script with the one from the previous exercise to make the sprite ‘walk’ as well as move around the screen how to experiment with different scripts including turn, repeat and if on edge, bounce how to use the up and down and left and right arrow keys to move the sprite how to use the ‘change x by’ and ‘change y by’ instructions to move the sprite horizontally or vertically that there is more than one way to create the movement Contents Exercise 1 – Understanding the Scratch Interface ......................................................................................... 2 Exercise 2 – Creating a Program for Simple Movement ............................................................................... 4 Exercise 3 – Simple Animation Using Costumes ........................................................................................... 6 Exercise 4 – Using the Keyboard to Control Your Sprite (Using If) ............................................................. 10 Appendix: Scratch Instruction Sets .............................................................................................................. 13

Lesson 1 Basics of Animation and Movementchulmleighict.weebly.com/uploads/1/4/1/8/14183906/_1.pdfwhat Scratch does and the basics of the Scratch interface how to create a simple movement

  • Upload
    others

  • View
    6

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Lesson 1 Basics of Animation and Movementchulmleighict.weebly.com/uploads/1/4/1/8/14183906/_1.pdfwhat Scratch does and the basics of the Scratch interface how to create a simple movement

Introduction to Scratch Programming v1.4 (Second Ed) 1 – Basics of Animation and Movement

Introduction to Scratch Programming (2nd Edition) Page 1 of 20 © ZigZag Education, 2013

Lesson 1 – Basics of Animation and Movement

What you will learn:

what Scratch does and the basics of the Scratch interface

how to create a simple movement program (called a script in programming language)

how to make the sprite reverse direction

how to make the movement go on forever (until you stop the program)

how to combine this script with the one from the previous exercise to make the sprite ‘walk’ as well as move around the screen

how to experiment with different scripts including turn, repeat and if on edge, bounce

how to use the up and down and left and right arrow keys to move the sprite

how to use the ‘change x by’ and ‘change y by’ instructions to move the sprite horizontally or vertically

that there is more than one way to create the movement

Contents

Exercise 1 – Understanding the Scratch Interface ......................................................................................... 2

Exercise 2 – Creating a Program for Simple Movement ............................................................................... 4

Exercise 3 – Simple Animation Using Costumes ........................................................................................... 6

Exercise 4 – Using the Keyboard to Control Your Sprite (Using If) ............................................................. 10

Appendix: Scratch Instruction Sets .............................................................................................................. 13

Page 2: Lesson 1 Basics of Animation and Movementchulmleighict.weebly.com/uploads/1/4/1/8/14183906/_1.pdfwhat Scratch does and the basics of the Scratch interface how to create a simple movement

Introduction to Scratch Programming v1.4 (Second Ed) 1 – Basics of Animation and Movement

Introduction to Scratch Programming (2nd Edition) Page 2 of 20 © ZigZag Education, 2013

Exercise 1 – Understanding the Scratch Interface

Scratch is software that allows the user to make simple programs for animating objects on screen. You simply drag and drop instructions to build up your program. By adding together the various blocks to code, you can make sophisticated games and animations. There are several areas on the main Scratch interface. It is important that you understand the basic function of each area.

This area lets you choose an instruction set.

This area shows the instruction set currently chosen. Each set is colour-coded.

Page 3: Lesson 1 Basics of Animation and Movementchulmleighict.weebly.com/uploads/1/4/1/8/14183906/_1.pdfwhat Scratch does and the basics of the Scratch interface how to create a simple movement

Introduction to Scratch Programming v1.4 (Second Ed) 1 – Basics of Animation and Movement

Introduction to Scratch Programming (2nd Edition) Page 3 of 20 © ZigZag Education, 2013

Click the start button to begin running your program. You can also choose to run your scripts by clicking the sprite or by other actions such as pressing keys on the keyboard. Click the stop button to finish running a script.

The stage is where the animation happens – you can also view animations in full-screen presentation mode by clicking the button to the top right of the stage.

Start the program by clicking here.

Drag an instruction to this area in order to add it to your scripts.

End the program by clicking here.

The stage is where the animation happens.

Click here for full-screen presentation mode.

Page 4: Lesson 1 Basics of Animation and Movementchulmleighict.weebly.com/uploads/1/4/1/8/14183906/_1.pdfwhat Scratch does and the basics of the Scratch interface how to create a simple movement

Introduction to Scratch Programming v1.4 (Second Ed) 1 – Basics of Animation and Movement

Introduction to Scratch Programming (2nd Edition) Page 4 of 20 © ZigZag Education, 2013

Exercise 2 – Creating a Program for Simple Movement

In Scratch, each character or object that appears on the stage is called a sprite. In this exercise, you will make a program that moves a sprite around the screen. By default, the sprite is a cat, but there are many other sprites that we can use and that we will see later.

1. Click on the orange Control button to show the Control options. A series of commands will appear

below the topics box. 2. Select the when green flag clicked command and drag it to the scripts area. 3. Next click the blue Motion button (to the left of the Control button). 4. Drag the move 10 steps button into the scripts area and lock it underneath the when clicked

command. 5. Click the green flag symbol near the top right of the Scratch screen to run the program. 6. Now every time you click the green flag the sprite will move 10 steps. 7. Change the amount of movement by changing the figure within the movement command. 8. Double-click on the value in the movement control and type in the value of 100.

Page 5: Lesson 1 Basics of Animation and Movementchulmleighict.weebly.com/uploads/1/4/1/8/14183906/_1.pdfwhat Scratch does and the basics of the Scratch interface how to create a simple movement

Introduction to Scratch Programming v1.4 (Second Ed) 1 – Basics of Animation and Movement

Introduction to Scratch Programming (2nd Edition) Page 5 of 20 © ZigZag Education, 2013

Changing Direction 1. Create this script. You will need to change the value of the move steps command from 10 to 100. 2. Click the green flag and observe the motion of the sprite.

Repeated Movement (Using Forever) Often we want the sprite to be animated continuously until we tell it to stop. In order to get the script that we have written to loop, use the forever instruction.

1. Follow the steps:

Only Face Left/Right At the top of the screen, where there is a small image of the sprite:

2. Click the middle button next to the image of the sprite. This makes the sprite face left or right to match

his movement.

Page 6: Lesson 1 Basics of Animation and Movementchulmleighict.weebly.com/uploads/1/4/1/8/14183906/_1.pdfwhat Scratch does and the basics of the Scratch interface how to create a simple movement

Introduction to Scratch Programming v1.4 (Second Ed) 1 – Basics of Animation and Movement

Introduction to Scratch Programming (2nd Edition) Page 6 of 20 © ZigZag Education, 2013

Exercise 3 – Simple Animation Using Costumes

An important concept to understand is that each sprite in Scratch can have many different costumes. During the program we can get the sprite to switch between one costume and another. The cat comes with two costumes (you can add others).

1. Rename the costumes as catwalk1 and catwalk2.

If you have a lot of costumes, it’s a good idea to give them sensible names.

Page 7: Lesson 1 Basics of Animation and Movementchulmleighict.weebly.com/uploads/1/4/1/8/14183906/_1.pdfwhat Scratch does and the basics of the Scratch interface how to create a simple movement

Introduction to Scratch Programming v1.4 (Second Ed) 1 – Basics of Animation and Movement

Introduction to Scratch Programming (2nd Edition) Page 7 of 20 © ZigZag Education, 2013

2. Create the script as shown to make the cat sprite appear to walk.

3. Try this alternative script.

This option is fine when you want only to repeat a cycle through existing scripts. You could have 10 costumes and cycle through them in a continuous animation.

Page 8: Lesson 1 Basics of Animation and Movementchulmleighict.weebly.com/uploads/1/4/1/8/14183906/_1.pdfwhat Scratch does and the basics of the Scratch interface how to create a simple movement

Introduction to Scratch Programming v1.4 (Second Ed) 1 – Basics of Animation and Movement

Introduction to Scratch Programming (2nd Edition) Page 8 of 20 © ZigZag Education, 2013

Combining Scripts 1. If you use this script at the same time as the walking script created previously, the cat should walk

back and forth across the screen.

Improving the Script 2. Now experiment with different movement scripts to change the movement of the sprite. This one

introduces the repeat command.

Page 9: Lesson 1 Basics of Animation and Movementchulmleighict.weebly.com/uploads/1/4/1/8/14183906/_1.pdfwhat Scratch does and the basics of the Scratch interface how to create a simple movement

Introduction to Scratch Programming v1.4 (Second Ed) 1 – Basics of Animation and Movement

Introduction to Scratch Programming (2nd Edition) Page 9 of 20 © ZigZag Education, 2013

Making Scripts More Efficient The first script uses the turn command, but there is no point in repeating the same command. Making your scripts more efficient is something to aim for.

If on Edge, Bounce Note the introduction of the ‘if on edge, bounce’ command. This stops the sprite from wandering off the edge of the stage. Save this project in your user area with the file name catwalk2.

Page 10: Lesson 1 Basics of Animation and Movementchulmleighict.weebly.com/uploads/1/4/1/8/14183906/_1.pdfwhat Scratch does and the basics of the Scratch interface how to create a simple movement

Introduction to Scratch Programming v1.4 (Second Ed) 1 – Basics of Animation and Movement

Introduction to Scratch Programming (2nd Edition) Page 10 of 20 © ZigZag Education, 2013

Exercise 4 – Using the Keyboard to Control Your Sprite (Using If)

It is possible to control your sprite using the mouse keys. In this exercise, we want the sprite to move exactly up and down vertically or side to side horizontally. Therefore, we will use the change x by and change y by instructions in order to ensure the correct movement of the sprite.

1. Before completing this exercise, dump your existing script into the left-hand side of the screen (this will

delete it).

7. Now use the copy stamp tool to copy the ‘if section’ of the script and then edit each script for each movement of the cat according to which arrow key is pressed.

8. Click on the Copy (stamp symbol) tool and then click on the word if in the script. This will create a copy of that part of the script.

9. Repeat this process twice more in

order to create the scripts for each different movement of the sprite (four ifs in total: up, down, left and right).

2. Start a new script with the when green flag clicked and forever instructions.

3. Choose the if instruction and drag in the key pressed instruction from the Sensing instruction set.

4. Set the key pressed to down arrow.

5. Add the point in direction and change y by instructions. 6. Set point in direction to 180 and change y by to -10.

Page 11: Lesson 1 Basics of Animation and Movementchulmleighict.weebly.com/uploads/1/4/1/8/14183906/_1.pdfwhat Scratch does and the basics of the Scratch interface how to create a simple movement

Introduction to Scratch Programming v1.4 (Second Ed) 1 – Basics of Animation and Movement

Introduction to Scratch Programming (2nd Edition) Page 11 of 20 © ZigZag Education, 2013

10. Drop the three new copied sets of instructions inside the forever instruction (not inside the existing if instruction).

There are often different ways to create the same effect. There may be no right or wrong answer – it’s for you to decide how to design your scripts. This alternative scripting uses ‘move 10 steps’ instead of ‘change x or y position by’. This scripting works just as well. Whichever commands you choose, you will also need to include a command that makes the sprite bounce off the edge of the stage. Look in the blue Motion instruction set and choose ‘if on edge, bounce’.

11. Set the key pressed to up arrow. 12. Set the point in direction to 0. 13. Set the change y by to 10. 14. Set the key pressed to right arrow. 15. Set the point in direction to 90. 16. Set the change x by to 10. 17. Set the key pressed to left arrow. 18. Set the point in direction to -90. 19. Set the change x by to -10.

Page 12: Lesson 1 Basics of Animation and Movementchulmleighict.weebly.com/uploads/1/4/1/8/14183906/_1.pdfwhat Scratch does and the basics of the Scratch interface how to create a simple movement

Introduction to Scratch Programming v1.4 (Second Ed) 1 – Basics of Animation and Movement

Introduction to Scratch Programming (2nd Edition) Page 12 of 20 © ZigZag Education, 2013

This is one version of the finished script for the animation, movement and control section including the bounce off edge option. Remember that you can create different versions that have the same effect.

Page 13: Lesson 1 Basics of Animation and Movementchulmleighict.weebly.com/uploads/1/4/1/8/14183906/_1.pdfwhat Scratch does and the basics of the Scratch interface how to create a simple movement

Introduction to Scratch Programming v1.4 (Second Ed) 1 – Basics of Animation and Movement

Introduction to Scratch Programming (2nd Edition) Page 13 of 20 © ZigZag Education, 2013

Appendi x: Scrat ch Instruction Sets

Control Instruction Set (Orange) These commands set the framework for all of the programming in Scratch.

These commands start the action either by clicking the green button, pressing a key or clicking a sprite.

This command makes the action pause for the set number of seconds.

Use this holder when you want the action to carry on without stopping.

Use this holder when you want the action to repeat a set number of times.

These commands send a message to the other sprites.

This command makes the sprite react when it receives a message.

These commands make something happen if something else is happening.

This command makes the action stop until something else happens.

This command makes the action repeat until something else happens.

These commands stop a single script or all the scripts.

Page 14: Lesson 1 Basics of Animation and Movementchulmleighict.weebly.com/uploads/1/4/1/8/14183906/_1.pdfwhat Scratch does and the basics of the Scratch interface how to create a simple movement

Introduction to Scratch Programming v1.4 (Second Ed) 1 – Basics of Animation and Movement

Introduction to Scratch Programming (2nd Edition) Page 14 of 20 © ZigZag Education, 2013

Motion Instruction Set (Blue) These are commands to do with the motion of the sprite.

Move and turn clockwise/anticlockwise.

Face up down, left or right.

Instruct the sprite to face another sprite.

Go to certain coordinates.

Glide slowly to certain coordinates.

X coordinates are to the left or right;

y coordinates are up or down.

When checked, these show the position and direction of the sprite on the screen.

Page 15: Lesson 1 Basics of Animation and Movementchulmleighict.weebly.com/uploads/1/4/1/8/14183906/_1.pdfwhat Scratch does and the basics of the Scratch interface how to create a simple movement

Introduction to Scratch Programming v1.4 (Second Ed) 1 – Basics of Animation and Movement

Introduction to Scratch Programming (2nd Edition) Page 15 of 20 © ZigZag Education, 2013

Looks Instruction Set (Purple) These commands all do something to the appearance of the sprite.

These commands change the costume in use by the sprite.

These commands change the colour of the sprite.

These commands show text in a speech bubble.

These commands show text in a thought bubble.

These commands change size of the sprite.

These commands show or hide the sprite.

These commands change the way that sprites overlap.

Page 16: Lesson 1 Basics of Animation and Movementchulmleighict.weebly.com/uploads/1/4/1/8/14183906/_1.pdfwhat Scratch does and the basics of the Scratch interface how to create a simple movement

Introduction to Scratch Programming v1.4 (Second Ed) 1 – Basics of Animation and Movement

Introduction to Scratch Programming (2nd Edition) Page 16 of 20 © ZigZag Education, 2013

Sensing Instruction Set (Turquoise) These commands all do something when something else is happening. For example, use with the IF

command to make the sprite touch something.

These commands report if the sprite is touching specific colours.

This command asks a question and then waits for an answer to be typed on the keyboard.

These commands report the x or y position of the mouse pointer.

This command reports if the set key is clicked (you can choose which key).

This command measures the distance to a set object.

This command sets the timer to zero.

This command follows the x position of another sprite.

These commands report loudness of sounds detected by the computer microphone.

These commands work with an external control input plugged into the computer.

This command shows the answer.

This command reports if the mouse is clicked.

This command displays the timer on the stage.

This command reports if the sprite is touching specific sprites.

Page 17: Lesson 1 Basics of Animation and Movementchulmleighict.weebly.com/uploads/1/4/1/8/14183906/_1.pdfwhat Scratch does and the basics of the Scratch interface how to create a simple movement

Introduction to Scratch Programming v1.4 (Second Ed) 1 – Basics of Animation and Movement

Introduction to Scratch Programming (2nd Edition) Page 17 of 20 © ZigZag Education, 2013

Sound Instruction Set (Pink) These commands all do something with sounds.

These commands play sounds (you can choose which sound).

These commands play drum beats (you can choose which drum).

These commands play or change musical notes.

These commands change the volume of the sounds or music.

These commands change the tempo of music.

Page 18: Lesson 1 Basics of Animation and Movementchulmleighict.weebly.com/uploads/1/4/1/8/14183906/_1.pdfwhat Scratch does and the basics of the Scratch interface how to create a simple movement

Introduction to Scratch Programming v1.4 (Second Ed) 1 – Basics of Animation and Movement

Introduction to Scratch Programming (2nd Edition) Page 18 of 20 © ZigZag Education, 2013

Operators Instruction Set (Light Green) These commands are all to do with mathematical values.

Calculation operators: add, minus, times, divide

Range operators:

greater than, less than, equal to

Logical operators:

AND, OR, NOT

This command reports specified length of a word.

This command gives the remainder of a division.

This command performs a mathematical function (you can choose the function).

This command joins words together.

This command rounds the product of a sum.

This command reports the specified letter of a word.

Page 19: Lesson 1 Basics of Animation and Movementchulmleighict.weebly.com/uploads/1/4/1/8/14183906/_1.pdfwhat Scratch does and the basics of the Scratch interface how to create a simple movement

Introduction to Scratch Programming v1.4 (Second Ed) 1 – Basics of Animation and Movement

Introduction to Scratch Programming (2nd Edition) Page 19 of 20 © ZigZag Education, 2013

Pen Instruction Set (Dark Green) These commands are all to do with drawing on the screen.

This command clears all the drawings on the stage.

This command puts the pen up or down.

This command sets the colour of the pen.

This control sets the shade of the pen.

This command sets the thickness of the pen.

This command makes a single mark with the pen.

Page 20: Lesson 1 Basics of Animation and Movementchulmleighict.weebly.com/uploads/1/4/1/8/14183906/_1.pdfwhat Scratch does and the basics of the Scratch interface how to create a simple movement

Introduction to Scratch Programming v1.4 (Second Ed) 1 – Basics of Animation and Movement

Introduction to Scratch Programming (2nd Edition) Page 20 of 20 © ZigZag Education, 2013

Variables Instruction Set (Orangey Red) A variable is something that might change over time. In Scratch, we can use variables for all sorts of

purposes such as a countdown or score.

In this section, you can also create lists.

To start with, the variables section is empty. You have to tell Scratch what you want the variable to do. Start by clicking Make a variable, then give it a name.

Once you have made a variable, you have many choices such as:

whether to display it on the stage or not

what to set the variable to

whether you want the variable to change at any point

whether to show or hide the variable