One of the many types of games you can create with Scratch is the platformer game—think of the classic 2D Super Mario Bros. where Mario runs from left to right, dodging bad buys, and sometimes climbing up onto different platforms to do so, or to collect coins, etc.
Well, not just "climbing" up, but jumping!
Hopping from platform to platform is a key piece of any side-scrolling "platform" game, so let's reveal just how easy it is to make a character - or Scratch sprite - jump up and down.
At this point your child should probably already have their game built, but in addition, we want to make sure their costumes are built out as well. That is, the player character should have at least two costumes: "right" and "left" so that it changes directions with the arrow keys.
As a quick rundown, the walking right pose is created by drawing the character facing the right side of the screen. Then, right-click and "duplicate" the costume. Next, highlight the whole character and click "Flip Horizontal" in order to change the pose's direction.
Position Sprites
The platformer will use the right and left arrow keys to move the player character, and the up arrow to jump.
After jumping, the character will fall back down until they touch the "ground" color of the platforms (in this example, that's the purple color).
1. Position and resize your sprites on the game preview window.
2. Draw a Ground sprite for your character to stand on.
Tip: The "Ground" sprite's color needs to be the exact same color as the top of the Platform sprite. If you look at the GIF above, you'll see the ground is light purple as well as the top of the platforms.
Character Movement
The character sprite will move using keyboard controls.
1. Select the player character sprite and add "when right arrow key pressed" to the code area.
2. Attach a "switch costume to Right" and "change x" block with a value of "20."
3. Right-click and "Duplicate" the code block, and change the key to left arrow.
4. Change the costume to "Left" and the "x" value to "-20."
Jumping
Now, the main event!
But, while jumping in real life, you fall back to the ground without even having to think about it, right? Well, in Scratch, this "landing" doesn't happen automatically, so you'll have to code your character to do so. Here is how:
First, add a "when up arrow key pressed" to the code area. Then, attach a "repeat" block set to "15," and place "change y" by "10" inside of it.
Then, attach a "repeat until <>" block under the previous repeat block. Before going further, remember the tip above where we said the ground color needs to be the same as the top of the platform color? So, click the "color" variable" and then select the eyedropper tool from the "color" menu. From there, hover over the "Ground" color and then click to select it.
Inside the "repeat until" block, add "change y" by "-10."
Quick note: If there's a platform directly above your character, you might get stuck on the first jump. This happens because the top of your character is technically touching the ground color, and so it thinks it doesn't need to fall! Here is a fix:
In the "repeat 15" block, attach an "if <> then" block under the "change y" block. Then, add the color to the "if" brackets and select the bottom color of the platform and inside the "if" block, add "change y" by "-10."
And with all of that, your child should be well on their way to completing their Scratch creation—jumping and all! If you're looking to take the next step, check out our many summer camps in Scratch, Scratch coding classes or Online Private Lessons.