This lessons teaches you how to make a character jump and have gravity pull them back down to the ground in Scratch.
Create a new Scratch project and delete the cat sprite.
Go to the Scratch website using the link below and click on the 'Create' link in the blue bar at the top.
By default, each new project starts with the cat sprite already added. To delete the cat click on the x in the blue circle beside the cat in the sprite list.
Change it's size to 50% in the Sprite properties and then add the following code to the dino sprite:
To add a sprite from the sprite library follow these steps:
You can use search box or the filter links (Animals, People, Fantasy etc) to locate your sprite.
Use the sprite editor to draw a 'ground' sprite. Use the Rectangle tool to draw a green box and drag it so it covers the bottom half of the stage area.
Rename this sprite to 'ground' in the sprite properties.
You can create your own sprites using the sprite editor. To create a new sprite put your mouse over the Choose a Sprite button and then click on the paintbrush.
This create a blank sprite and will open the sprite editor where you can use the tools to create your sprite. You can even create extra costumes for your sprite!
Tip: give your sprite a name so that you can recognise it in the code blocks.
Create a variable called 'gravity' and then add the below code. This code makes the dino fall if it's not touching the ground.
We're going to program the space bar key to make the dino jump but the dino should only be able to jump if it's touching the ground (you can't jump in mid-air!!).
Add the following code to the dino:
Since your tablet or iPad doesn’t have a physical keyboard, you’ll use on-screen buttons to complete this task. Wherever the instructions in this lesson mention pressing a key, you’ll need to tap a button on the screen instead. So, while your steps are a little different, you’ll still be able to make everything happen in your project.
So for example, instead of doing either of these:
You need to add an on-screen button (like an arrow sprite) and use this code:
Now, just tap the button on the screen to perform the same action!