Please update your browser
Your browser version is not supported by this site. CS First may not work properly.
In this add-on, you will program each costume to start at a specific x position to set the
order in which they pass by.
To begin, add a start point parameter to the "create objects" function.
Right click the define "create objects" block, and click edit.
Under Options, click number input.
Name the parameter "start point."
Next, create a variable called "start point."
To make this variable a local variable, set it to "for this sprite only."
If you set it to "for all sprites," its value will be shared between clones, so setting
the variable for one clone will change it for all the others.
Each clone in this project will start from a different point, so the variable should
be set to “for this sprite only.”
Set this variable equal to the start point parameter in the "create objects" function.
Next, choose an order for the costumes to appear.
Type increasing values in the "start point" input.
In this example, the clouds appear first, followed by the mountain, and finally the
Program the character to keep track of the distance it has travelled.
Select the walking sprite, and create a variable called "traveled" because it’ll hold how
far the walking sprite has traveled.
Add a "change traveled" block under the "next costume" block in the "when right arrow key
pressed" block stack, and set the value to 20.
Add this same block in the "when left arrow key pressed" blockstack, and set the value
to negative 20.
Add a "set traveled to 0" block under the "when flag clicked" block to reset the variable
every time you start the program.
Next, program the clones to wait to appear until the character reaches its starting position.
Select the "objects" sprite, and add a "wait until" block under the "when I start as clone"
Add a "greater than" block.
On the left side, add the “traveled” block.
On the right side, add the start point variable.
Click the flag to test.
All the clones appear on the right side of the stage.
To make them hide until the distance traveled is greater than the clone's start point, move
the "show" block under the "wait until" block.
Move the "hide" block under the "when flag clicked" event.
Click the flag to test again.
The clouds start, then the mountain, and finally the peacock.
But, what if you start out by moving to the left!
Nothing will appear -- ever.
When the sprite moves to the left, the value of its “traveled” variable decreases.
If the sprite moves to the left of the starting point, its distance traveled becomes negative.
To fix this, make each costume appear when the absolute value of the “traveled”
variable reaches its starting point.
Taking the absolute value of a number makes it positive.
To do this, click the operators menu.
In the dropdown menu of the square root block, select "abs," which stands for “absolute
Put this block around the "traveled" block in the "wait until" block.
Click the flag, and move to the left to test.
It might be fun to make one of the costumes start really far out.
Now, it's your turn.
Add a start point parameter to the "create objects" function.
Create a variable called "start point."
Program the clones to wait until the walking sprite reaches its starting position before
Make each costume appear when the absolute value of “traveled” reaches its starting point.