A Scratch example with two sprites
Next step after the Meow World example
About four days ago a story how to install Scratch on Windows 11 was posted. There is also an example of Meow World in it 😄. Continuing that another example is presented in this story, where two sprites are used, a cat and a crab.
Each sprite will have its own code and could interact independently with user action.
Sprite
In Scratch, sprite is like a character, an image, or an object designed by the users that perform the action based on the script using various blocks of Scratch, where different sprites can have different scripts, costumes, sounds, and the ability to move based on the script instructions (Lath & Bindal, 2023).
In the example above we use to sprites, the first is a cat and the second is a carb. All sprites you use are displayed on the bottom left section of Scratch window.
Script
Each sprite has its own script.
As you can see in above figure, on the left is script for the crab, while on the right is script for the cat.
Run
To run the script press green flag on the upper right corner on the Scratch window as follow.
And the result is below.
The code is also available https://github.com/dudung/scratch-examples/tree/main/circular_motion. There is also MP4 version of the result on https://www.youtube.com/watch?v=l7AYhlDqQDQ.
The circular motion of each sprite is activated when each sprite is clicked.
Then it performs a forever loop.
Closing
After read this story you are able to
- create a circular motion with two sprites using given visual script, or
- download first the script and run it.
As a challenge, can you add a line to stop the sprite motions when it is clicked? Inform me the result by put the link of your work in the comment.
- Lath R, Bindal N (2023), “What Is A Sprite In Scratch Programming?”, Wiingy, 25 Jul 2023, url https://wiingy.com/blog/sprite-in-scratch/ [20240524].