Lessons
|
Movement
Movement in scratch can be as simple or a complex as you like.
Movement is controlled using the blue motion blocks. Using these blocks, you will be able to create Scratch applications that can move sprites around the stage, rotate sprites, point them in different directions, change sprite location, and detect collisions with the edge of the stage. Basic Movement and Rotation
Scratch provides access to three motion blocks that move sprites and rotate them
on their axis. The first of these blocks allows you to set the number of steps that a sprite should move on the stage. The second and third blocks allows you to set the number of degrees that the sprite can rotate clockwise or counter clockwise. Pointing in Different Directions
Scratch provides access to two motion blocks that can be used to point a sprite in a specified direction or to point a sprite towards the mouse-pointer or a specified sprite.
The first block allows you to point a sprite in any particular direction. You have to set the direction by typing in a number that represents the number of degrees that the sprite should be turned. You can either select a value of from the block’s drop-down list or type in an integer value in the range of 0 to 360. Remember the following numbers:
The second motion block allows you point a sprite towards either the mouse-pointer or another sprite. The following script shows how this block can be used to make the sprite continuously point towards the mouse-pointer as it moves around the stage. Changing Locations
Scratch provides access to three motion blocks that move a sprite to a specified location on the stage, move a sprite to the location currently occupied by the mouse-pointer or another sprite, or move a sprite to a specified position over a specified number of seconds.
The first block allows you to reposition a sprite to any location on the stage by specifying X-axis and Y-axis coordinates for the sprite. You have to set the coordinates by typing in the values for the x and y axis. Use this block to make the sprite jump to a new location. Hint: This is the block that you use to make a sprite in a game go to a starting position. It is important to remember the size of the stage so that you know where to place the sprite on the stage.
The second block allows the sprite to move to the current location of the mouse-pointer or another sprite. With this block you can program the sprite to follow your mouse-pointer around the stage. See the example below.
The third block allows you to reposition the sprite by moving or gliding to its new position a smooth motion. This is very different than the first block. The sprite will not disappear and suddenly appear in a new location. This block also allows you to control the time it will take the sprite to glide to its new location.
Bouncing Sprites Around the Stage
As a sprite is moved around the stage, it may eventually come into contact with one of the edges of the stage. Using the motion block shown on the left, you can instruct Scratch to bounce the sprite off of the edge of the stage.
The following script demonstrates how to use this code block to bounce a sprite around the stage. This script reverses the direction that a sprite is traveling whenever it collides with the edge of the stage. If you were to add this script to the cat sprite in a new application, the cat would move across the stage from side to side until you halted the application’s execution. |