Motion Blocks: X-Y Block, Glide Block, Change and Set X-Y Blocks
Understanding Coordinates in Scratch
To understand X-Y, Glide and Change and Set X-Y blocks, first we have to understand the X-Y coordinate system in Scratch.
Scratch uses a coordinate system to determine where sprites are placed on the Stage.
- The X-axis represents horizontal movement:
- Left direction: Negative values (-240 is the left edge).
- Right direction: Positive values (240 is the right edge).
- The Y-axis represents vertical movement:
- Upward direction: Positive values (180 is the top edge).
- Downward direction: Negative values (-180 is the bottom edge).
- The center of the stage is (0,0), meaning:
- X = 0 places the sprite in the middle horizontally.
- Y = 0 places the sprite in the middle vertically.
Understanding this system helps in placing sprites accurately and controlling their movements.
Advanced Motion Blocks
1. Go to X-Y Block
This block moves the sprite instantly to a specific location based on the given X and Y coordinates. It is useful when you want to position your sprite precisely without any animation.
To set the coordinates of the block, move your sprite to that specific position.
- Example 1: "Go to X: 100, Y: 50" moves the sprite immediately to (100,50). {Implement this}
- Example 2: Make an animation where a dog sprite moves between three different locations. {Implement this}
In this, we have to use the Wait Sec block also. This block makes a time gap between different Go to X-Y blocks.
- This is helpful in designing games where objects need to be placed at exact locations.
2. Glide Block
Unlike the "Go to X-Y" block, the Glide block moves the sprite smoothly over time to a specific coordinate, creating an animation effect.
To set the coordinates of the block, move your sprite to that specific position.
- Example 1: "Glide 2 Secs to X: 100, Y: 50" makes the sprite smoothly transition to (100,50) over 2 seconds. {Implement this}
- Example 2: Make an animation where a butterfly sprite glides between three different locations. {Implement this}
- This block is widely used for animations, character movements, and game object motion.
3. Change X-Y Blocks
These blocks allow movement relative to the sprite’s current position, rather than an absolute location.
- Example 1: Change X by 10: Moves the sprite 10 steps to the right. {Implement this}
- Example 2: Change Y by -10: Moves the sprite 10 steps downward. {Implement this}
- This is useful for creating continuous movement, such as a character moving right when an arrow key is pressed.
4. Set X-Y Blocks
This block is similar to "Go to X-Y" but is mainly used for setting a sprite's initial position at the beginning of a project.
- Example: Set X to 0, Y to 0 places the sprite exactly at the center of the stage.
- This block is useful for resetting positions in games when restarting a level.
Project: Animated Scene Using Set and Glide Blocks
Objective: Create an animation where a sprite moves between three points in a smooth looping motion.
Steps:
- Open Scratch and choose a sprite (e.g., a bird or a car).
- Drag a Go to X= -200, Y=0 block and connect it to When Green Flag Clicked (This ensures the sprite always starts at the same position).
{Explain When Green Flag Clicked Block}
Green Flag Block ensures that the game starts from its starting position. You have to click the Green Flag to start the game again. This block is present in the Events section.
- Add a Glide 2 Secs to X: 0 Y: 100 block (The sprite moves smoothly to a new location).
- Then, add another Glide 1 Secs to X: 200 Y: -100 block (Moves to another location smoothly).
- Finally, add Glide 2 Secs to X: -200 Y: 0 (Back to the starting position).
- Click the Green Flag and watch the animation!
✅ Expected Outcome: The sprite glides between three points, creating an animated movement effect.