Add Code to Animate a Turtle or Other Animal in Scratch
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
Click the Turtle sprite and then click the Scripts tab.
Drag the following blocks into the Scripts Area so they snap together:
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.
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.
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?
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.
Click the Costumes tab.
Rename the current costume Right.
Shift-click that costume and select Duplicate.
Click to select the copy and rename it Left.
Click the Flip Up-Down button.
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.
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?!?