Creative Coding (Day 3)

Scratch uses what is called a Cartesian Coordinate system.

Left and right are represented by “x”.
Up and down are represented by “y”.

Increasing “x” will move your sprite to the right. Decreasing “x” will move it to the left.
Increasing “y” will move your sprite upwards. Decreasing “y” will move it downwards.

Setting “x” to 240 will move your sprite to the right edge of the screen, and -240 will bring it to the left edge.
Setting “y” to 180 will move your sprite to the top edge of the screen, and -180 will bring it to the bottom edge.

Using “go to x y”, “set x”, and “set y” blocks will move your sprite immediately to that position. For example, “go to x: 0 y: 0” will move your sprite to the center of the screen. Using it repeatedly will not move your sprite anymore.

The “change x” block will move your sprite left or right. If you run “change x by 10”, it will move your sprite 10 steps to the right. If you run the block again, it will move it another 10 steps to the right. Running “change x by -10” will move it 10 steps to the left.

The “change y” block will move your sprite left or right. If you run “change y by 10”, it will move your sprite 10 steps up. If you run the block again, it will move it another 10 steps up. Running “change y by -10” will move it 10 steps down.

Controlling your sprite (method 2)

Instead of using the “when key pressed” event, you can also control your sprite using a “forever” loop and a “if key pressed” block. In the above example, the sprite will keep on moving upwards as long as the “up arrow” is pressed.

This method is slightly more complicated than the “when key pressed” method, but can provide a smoother movement.

Broadcast Events

Broadcast are used to start a script in another sprite. When a sprite runs the “broadcast message” block, all the sprites that have the “when I receive message” event will run the code under it.

In our “Dog, Cat, and Mouse” program, our cat sprite sends a broadcast message when it touches the mouse. The mouse receives the message and moves to a new random position.