Please update your browser
Your browser version is not supported by this site. CS First may not work properly.
In this video, you will program more functions that animate the android’s actions.
In the previous video, you learned that you could make a new block to animate your android.
If you did those same steps for all of your animations, your code would look something
That is one way to create animations, but as an advanced CS First student, you might
notice that many stacks in this code look similar to each other.
Instead of repeating code stacks over and over, make a function, or a new block, that
will achieve the same effect with fewer code blocks.
This saves time and effort and makes your code easier to read.
Create a function that changes the sprite's costume a specific number of times to complete
one animated action.
To start, make a new block, and name it "Animate Action."
To make the costumes repeat like those in your first animation, drag the “repeat”
loop, “next costume” block and “wait” block you previously coded under the “define
‘animate action’” block.
To make this code stack start and stop at specific times, add a parameter, or input,
to the block’s definition.
This parameter will specify how many times the costume should change.
In computer science, a parameter gives information that slightly changes the behavior of the
For example, the "Animate Action" function might switch costumes 4 times for a certain
action, but 8 times for another action.
The parameter input specifies how many times the costume switches.
When you add a parameter to a block’s definition, it creates an input space, so that users can
add another block or value to the code.
Right click on the define block, and select “edit.”
Then, click the Options dropdown menu, and select “Add number input.”
Name this input “Costumes."
Next, drag the newly created “costumes” parameter inside the repeat loop.
Now, put this block to use!
This example for the Happy animation has 10 costumes.
The happy animation needs to cycle through 9 “next costume” blocks to complete the animation.
In this example, the “switch costume to happy1” block should remain under the “define
Drag the "Animate Actions" block under the “switch costume to happy1” block.
Change the value in the "Animate Actions” block to the correct number for your animation.
This example uses 9.
Test the code by clicking the "action" block you created.
The sprite animates the action, just like before.
You now have one animation working, but your starter project contains several animations
to use throughout your story.
To create those animations, define a new block for each and add a “switch costume” block
to set the android to the starting costume.
Next, add an "Animate Action" block, and enter the number of costumes for the animation.
Do this for all the sprite’s actions, then add those actions to your story.
Now, it’s your turn.
Create a function, and use it to define the android actions.
Then, add the "action" blocks throughout your story!