Hello, brilliant parents and teachers! Are you ready to add a new dimension to your child’s animations? Up until now, characters have moved at the default speed, but today we’re going to learn how to control movement with the Set Speed block in ScratchJr. This is a fantastic way to introduce concepts like variables and rate of change in coding.
The project we’ll use to master this skill is a fun race: Kitten and two friends having a race in the park. This will demonstrate how the same code can produce different results based on the speed setting.
Setting Up Your Race Track
Before we code, we need our scene and our racers ready:
- Change the Background: Select the park background for the race track. [00:25]
- Add Racers: Add two friends to race alongside Kitten, such as Tack and Dragon. [00:39]
- Adjust Size: If a character (like Dragon) is too large, you can use the Shrink block a few times before starting the main programme to make them a more appropriate size. This doesn’t affect the code. [00:59]
- Position Racers: Line up all three characters at the starting line.
Coding the Race: The Set Speed Block
Every racer needs the same core movement code, but with a different speed setting. We can use a clever trick to save time when coding!
Coding Kitten (Fast Speed)
Kitten will be the fastest racer. Ensure the Kitten icon is selected.
- Start Block: Begin with the Green Flag trigger block (yellow category).
- Set Speed: Go to the orange Control category and add the Set Speed block. [01:35]
- Choose Speed: Click the downward arrow on the Set Speed block. Select the fastest icon (the icon with the most dashes, usually on the right). [02:08]
- Movement: Go to the blue Motion category and add the Move Right block. Set the number to a high value (e.g., 18) to make them move right off the screen. [01:42]
- End: Finish the script with the red End block.
Coding the Other Racers: The Drag-and-Drop Trick
Since Tack and Dragon need the exact same movement code, we can copy Kitten’s script to save time, and then just change the speed!
- Copy the Code: Click and hold the entire stack of Kitten’s code. Drag the code and drop it onto the Tack icon on the left. [02:20]
- Edit Tack’s Speed: Click the Tack icon. The copied code will appear. Click the Set Speed block and change it to the medium speed icon. [02:33]
- Copy to Dragon: Repeat the copy process: grab Tack’s code stack and drop it onto the Dragon icon. [02:44]
- Edit Dragon’s Speed: Click the Dragon icon. Change the Set Speed block to the slowest speed icon. [02:49]
Running the Programme
When you press the Green Flag, all three characters start moving at the same time, but at drastically different speeds, showing the immediate effect of the Set Speed block! Kitten is fastest, followed by Tack, and Dragon comes in last. [03:07]
This project is an excellent addition to our coding tutorials. It shows young coders how to reuse code and control variables. For more structured activities and curriculum, explore our comprehensive collection of lessons. Happy coding!