Add Code to Animate a Turtle or Other Animal in Scratch - dummies

Add Code to Animate a Turtle or Other Animal in Scratch

By Derek Breen

If you’ve gone to the trouble of creating a ferocious turtle or other animal in Scratch, then you might want to add some basic animation.

If you have trouble locating one of the code blocks, try looking for the category that matches the color of the block.

Make the turtle crawl

  1. Click the Turtle sprite and then click the Scripts tab.

  2. Drag the following blocks into the Scripts Area so they snap together:

    image0.jpg

Click the Green Flag button on the top-right side of the Stage to test your code. What happens? Fastest turtle you ever saw, right? He scoots right off the side of the stage.

Slow down the turtle

You can bring the turtle back to the center and slow him down by adding a GO TO block and a WAIT block.

image1.jpg

Change the values in the GO TO block so X is 0 and Y is 0. X is the horizontal position and Y is the vertical position. When X and Y equal 0, the block should move a sprite to the center of the screen.

Now when you click the Green Flag button, the turtle should jump back to the center of the screen and then start moving, VERY slowly. Can you figure out how to speed the turtle up a little?

Speed up the turtle

Click the Stop button on the Stage. You can either have the turtle move more than ten steps at a time or reduce the WAIT time. Try changing the MOVE value to 5 and the WAIT value to .25. Also, add a block that tells the turtle what to do when it reaches the edge of the stage.

image2.jpg

Now when the Green Flag button is clicked, the turtle should move a bit faster and, when it gets to the edge of the stage, flip around and start crawling in the opposite direction. The turtle will crawl back and forth, back and forth, for as long as you can stand to watch it!

Not too exciting, right? What if you shrink the turtle to give it more room to move around, and have it turn occasionally?

image3.jpg

Add another WHEN GREEN FLAG CLICKED block and then snapped new blocks under it. One set of blocks moves the turtle to the center and then makes the turtle move forward, while another set of blocks makes the turtle smaller and then makes the turtle turn a bit every second.

Animate the turtle legs

What if there were an easy way to make it look like the legs are moving? Here’s a cheap trick to make the movement more realistic.

  1. Click the Costumes tab.

  2. Rename the current costume Right.

  3. Shift-click that costume and select Duplicate.

  4. Click to select the copy and rename it Left.

  5. Click the Flip Up-Down button.

    image4.jpg

Now click the Scripts tab and add this third set of blocks. Be sure to change the costume names to Right and Left and the value of the WAIT blocks to .25.

image5.jpg

Did you click the Green Flag button yet? What are you waiting for?!?

If all your blocks are in the right place, you should have a pretty realistic little turtle waddling around the stage. Cool, right?!?