In this video, you will create different animations for your monster by making it change costumes multiple times.
Select the costumes tab.
You will see several costumes that reflect different emotions.
First, program the sprite to show a happy emotion.
To do this, change costumes quickly to express the monster’s happy animation.
Click the “scripts” tab.
Snap together three “switch costume” blocks.
Change the dropdowns to “happy1, happy2, and happy3.”
Add “wait” blocks after the costume changes so that the program waits to run each block.
That way, you can see the animation.
Next, code the animation to happen continuously.
Add a “repeat” loop around the “switch costume” blocks.
Test it out.
Next, program a sad emotion.
One way to do that would be to copy the entire block stack you just made, but that would be very repetitive.
In computer science, you can use a different approach to create the same functionality with less code.
Whether the monster is changing to different “happy” or “sad” costumes, it uses “switch costume” blocks.
Make the monster switch costumes without repeating all those blocks.
Use a variable to set the feeling, and tell the code to determine which costume to use based on that variable.
Recall that a variable stores information or values that change, so the program can use it.
This example will use a variable for the feelings, so that when the happy, sad, or angry feeling is set, the variable determines which costumes to use.
Make a variable, and name it something that makes sense, like “feeling.”
Place the “set feeling” block above the “repeat” loop.
Type “Sad” into the space in the block.
Note that the costume names in the “sad” animation contain the word “sad” and also a number that represents the order it appears.
Your variable contains "sad," but it needs the number to complete the costume name.
From the operators menu, drag out a "join" block, and place it inside the "switch costume" block.
Then, place the "Feeling" variable into the first value of the “join” block, and type the number 1 in the second value.
The block can be read as "switch costume to sad1.”
Click the block to test it.
The monster changes its expression to the "sad1" costume, then changes to happy2 and happy3.
Change the value of the variable to "happy" and click the block.
The monster changes to the "happy1" costume.
Duplicate the join block, and change the costume numbers, creating a costume change for numbers 2 and 3.
Add a “when flag clicked” block, then test this by clicking the flag.
The happy expression animates.
If you type “sad” inside the “set feeling” block, the sad expression animates.
Lastly, to make the expression continuously animate until you change the emotion, replace the “repeat” loop with a “forever” loop.
That way, your animation doesn’t have a definite stopping point.
Feel free to tinker with the values in the "wait" blocks to make the costumes change quicker or slower.
This example uses a value of 0.2 in each "wait" block.
In the next video, you will program the monster to say a message and express an emotion that goes with it.
Now, it’s your turn.
Create a “feeling” variable.
Then, code your monster to animate different expressions using the “feeling” variable, “switch costume,” “wait,” “join” and “forever” blocks.
Set the starting emotion with the “set feeling” block and a “when flag clicked” event.
- Create a "feeling" variable.
- Program the monster to animate different expresions.
- Set the starting emotion.