Code Your Sprite to Change Costumes

Code Your Sprite to Change Costumes

1.  We are going to animate our Sprite by changing its costumes. I’m going to animate the Dragon Sprite to breathe fire. Start by adding a “when this sprite clicked” Events block into your Code Area.


2. Drag a “switch costume to…” block from the purple Looks category in the Block Palette and snap it underneath the “when this sprite clicked” block in the Code Area.


3.  Click the drop-down menu on the “switch costume to…” block and choose the costume that you would like your Sprite to switch to. I’m going to choose costume dragon-c because I would like it to breathe fire!


4. Click on the Controls category in the Blocks Palette. These blocks control your scripts, like how many times your code will run or make blocks in your script wait a few seconds before running. Click and drag a “wait 1 seconds” block onto your Code Area and snap it underneath the “switch costume to…” block.


To change the amount of wait time before the sprite changes from one costume to the next, you can change the number inside the white input bubble by clicking on it. For this episode, I have set the seconds to 0.3. This will make the costumes switch quickly and look more seamless than if I had the wait time for one second.


5. Add another “switch costume to…” block from the Looks category underneath the “wait 1 seconds” block.


6. Click on the drop-down menu on the “switch costume to…” block and choose a different costume than the one in your first Looks block. I’m changing the costume to dragon-a.


7. Now you will want to add one more wait block underneath the second “switch costume to…” block. Make sure you change the input number on this block to match the first wait block. As you can see below, both of my wait blocks have the number input of 0.3.


8. Now you are ready to test your code! Click on your sprite and watch it switch between costumes. You’ve animated a sprite! Play around with choosing different costumes and different inputs to see how the animation of your sprite changes. What happens if you put a large number in the wait block? What happens if you put in a smaller number?



Views
1 Total Views
1 Members Views
0 Public Views
Share on Social Networks
Share Link
Share by mail

Please login to share this webpage by email.