Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

arrow_back Starting Point

Transcript

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 peacock.

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" block.

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.

Oh no!

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.

Great!

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 value.”

Put this block around the "traveled" block in the "wait until" block.

Click the flag, and move to the left to test.

Awesome!

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."

Set this variable equal to the start point parameter in the "create objects" function.

Program the clones to wait until the walking sprite reaches its starting position before appearing.

Make each costume appear when the absolute value of “traveled” reaches its starting point.

Choose an Add-On
play_circle_filled
Starting Point
Set the order in which the objects pass by.
arrow_forward
play_circle_filled
Walk to the Beat
Play music when the character moves.
arrow_forward
play_circle_filled
Day & Night
Change the day to night as the character moves forward.
arrow_forward
play_circle_filled
Passing By
Program the objects being passed to respond to the character.
arrow_forward
play_circle_filled
Scenery Change
Set costumes to a random color when they appear.
arrow_forward
arrow_backward Back
Next arrow_forward