WEBVTT

00:00.000 --> 00:22.960
Welcome to the video, too, of making your sprite move left and right.

00:22.960 --> 00:27.440
Let's now move your sprite to the location on the stage that you want it to start at.

00:27.440 --> 00:36.560
I want my card to start here, and you can see that this location on the grid is x-133 and y-66.

00:36.560 --> 00:38.640
Now let's add some code.

00:38.640 --> 00:43.180
Go to the yellow events category here, and grab a Wing Green flag clicked.

00:43.180 --> 00:45.480
Drag this into your code area.

00:45.480 --> 00:51.040
Next, go to the blue motion category here, and grab a go to x, y-block.

00:51.040 --> 00:55.280
Snap this right underneath the Wing Green flag clicked in your code area.

00:55.280 --> 01:00.920
Now you see that this block has the same coordinate values as the values in the sprite's pane.

01:00.920 --> 01:06.200
x is minus 133, and y is minus 66.

01:06.200 --> 01:09.600
This means that we don't have to change these numbers.

01:09.600 --> 01:15.280
Now watch what happens when I move the car anywhere else on the stage, and then press the green flag.

01:15.280 --> 01:20.080
My car goes back to the location that I've set in this x, y-block.

01:20.080 --> 01:24.080
Now we're ready to add our code that will move the car left and right.

01:24.080 --> 01:31.000
Go to the events category again, and now grab a one-space key, press block, and drag it into your code area.

01:31.000 --> 01:34.480
Click the drop-down menu and choose the right arrow.

01:34.480 --> 01:36.800
Now we've started a new event.

01:36.800 --> 01:41.720
So whatever code we add under here will only run when we press the right arrow.

01:41.720 --> 01:45.920
It won't run when we press the green flag because that's a different event.

01:45.920 --> 01:53.000
Go back to the blue motion category here, and grab a chain jacks by block, which is right down at the bottom.

01:53.040 --> 01:57.720
Snap this right underneath the right arrow, key press block in your code area.

01:57.720 --> 02:04.560
This block is telling us that it will change the value of x by 10 every time we press the right arrow on our keyboard.

02:04.560 --> 02:07.440
Now where do you think this sprite will move?

02:07.440 --> 02:10.080
To the right or to the left?

02:10.080 --> 02:16.560
If we are increasing the number by 10, or making the value of x bigger each time we press the arrow key?

02:16.560 --> 02:18.040
Let's see.

02:18.040 --> 02:22.560
Every time I press the right arrow, my car sprite moves to the right.

02:22.560 --> 02:29.280
And you can see that the value of x in the sprite's pane here will increase every time my car moves to the right.

02:29.280 --> 02:35.320
And if I want to bring my car back to that starting location, I just simply press the green flag.

02:35.320 --> 02:37.600
Please continue to video three.

02:37.600 --> 02:38.600
Thanks for watching.

