Scratch is one of the most popular programming languages for kids. It uses colorful, pre-made “Blocks” of code that click together like LEGO to form scripts, allowing kids to learn computer science concepts through hands-on development of their own games, digital art, and animations. Kids build scripts of multiple blocks to animate sprites, or in-game characters and objects, to move, change, and interact with each other.

If you like building programs in Scratch, or if you are a fan of platforming games, then learning how to make your sprite jump is a key skill that every game designer should learn. While making a character walk back and forth on the screen is relatively easy, learning to make a sprite jump and interact with objects in Scratch requires some careful coding and is an intermediate skill when it comes to game design. If you haven’t tried Scratch before, you might want to begin with a free trial class at Create & Learn to learn the basics before taking on this challenge.

How to make a Sprite jump in Scratch simply

Making a character jump can actually be relatively easy (we know we just said the opposite), but remember that there are two questions to ask when building any program: 1. "Does it work the way I want it to?" 2. "Is it well designed?"

The first question is easy to answer: a program that doesn’t work could be described as “broken” and might contain one or more bugs that prevent the game or program from running as desired. The second question is a bit harder. We can design simple programs that do a basic task quite easily, but making things run elegantly, simply, and efficiently can be much harder. We will first break down how to make a sprite jump simply in Scratch, and then we will show you a more advanced way to do it that involves simulating gravity while falling.

1. Paint the Ground

Begin this project by choosing a sprite as your player character. Then you want to use the paintbrush in the pop-up “Sprite selection” menu in the bottom left corner. This will allow you to use the rectangle tool to create some platforms for your sprite to stand on. Here we have chosen a dinosaur sprite and a mud colored box sprite as my ground.

Paint the Ground by selecting a Sprite
Paint ground in Scratch

2. Create a “Y Velocity” Variable

Viewing the Stage window on Scratch as a Cartesian Plane, the Y-axis determines the vertical location of a sprite on the stage. When a character moves up from their starting position, their Y value increases, and when it moves down the Y value decreases. So we want to associate the pressing of a button on the keyboard with an increase in the Y value of the sprite. But this value could change, depending on the location of the Ground sprite or its shape, for example if it has ramps, pits, or obstacles that need to be jumped over. When we have a changing value in a program, we should use a Variable that will store that value at any moment.

Y variable

3. Create Some Gravity

Now that we have a yVelocity variable, we can use that variable within a loop to create a sensation of gravity. By setting the variable to -1 and placing the variable with the “Change y by __” block, it makes the Character sprite seem to fall. By creating a condition within our loop that resets the variable to zero when touching the color of the ground. If you use the mouse to position your sprite above the ground and click the green flag, it will fall and stop. Use the color sensor within the Sensing block to get the exact color and shade of the ground block.

4. Jump

Now, you have to create a parallel string of blocks that activates when pressing a key on the keyboard. Use the Event block for this, then by setting the Y value to 10 whenever the Space key is pressed, my Y value goes up suddenly, but because of the previously built “gravity” string, our action is always met with the falling after the jump.

5. It works, but is it well designed?

It’s not perfect, but it works. It’s a simple jump. If you play around with the code at this stage, you will notice some features that might not make for a great game. For example, if I hold the Space key down, the dinosaur stays jumping and basically flies. If I double tap, he does multiple jumps. And instead of standing on the ground, my sprite actually floats in the middle of the platform and vibrates very slightly. There’s no other controls, no backdrop, no music, it feels a little buggy.

How to make a Sprite jump in Scratch creatively

We will want to add some other features later, but most importantly, we want our sprite to sense a changing environment, not simply the same platform in the same location forever. If you add some other sensing conditions to move left and right you will have the basic mechanics of a platformer game, which is a powerful tool for any children who love coding and games to learn. Keep reading if you want to find out how to make a sprite jump in Scratch in a more elegant way.

1. Follow steps 1 and 2 from above

In this more challenging version, we’re going to create a ground sprite, a character sprite and a y variable to create a platform and the sense of gravity in our game.

Jumping in Scratch

2. Gravity Is Constant, But Coding It Isn’t

The main bug in our first program was that gravity was not fully respected. If the player held down the space key, the jump would last forever, which could be part of your game, but would probably make it too easy and not very fun to play because it ignores the Law of Gravity.

Gravity is the attractive force of any object. Every giant galaxy and every tiny particle in the universe has some gravity, but objects of greater density like stars, planets, and black holes emit stronger forces of gravity, which pulls humans and monkeys toward the Earth when we jump, the Earth and the other planets of the Solar system toward the sun, and the Solar system itself towards the supermassive black hole at the center of the Milky Way. Without any equal or more powerful force to counteract gravity, such as the force of human muscles jumping or a rocket engine propelling a shuttle towards outer space, there would be no jumping, flying, or even walking.

3. Play Around with the Y Variable

In this version of the game, we have the same idea in our basic loop: a yVariable, a “change by y” block, and a conditional within a forever loop that senses something. This version is different because instead of sensing the color, you can sense the Sprite itself. Now your ground can vary in color, shade, or even costume (giving you a totally different sprite as your Ground), which makes the game more interesting and easier to change later on by simply adding new costumes to the sprite. In this version, instead of always falling, the Character sprite is held to the ground just like gravity keeps us walking on the street instead of flying through the air. Also in this version, we have included the command using the Space key as a conditional within our forever loop, rather than a separate string of code. We could say this is simpler, but both methods work. Experiment to see which one works better for you.

Y Variable

4. Create a SitStill block

At this point, you might notice a bug that was present in the simpler version above. The character jumps because the y value changes when you press the space key, and then it falls because of our use of the different settings for the variable, but the sprite vibrates slightly when standing on the platform. Go to the “My Blocks” menu on the left hand side of the screen. Then “Make a block” which you can name, “SitStill.” Make sure to click the box that says, “Run without screen refresh.” Now, using a conditional block and the “Not” operator and a sensing block, we will adjust the Y value in such a way that it always rests between 1 and -1 when touching the platform. The math is a little complicated, but when you place the SitStill block within your main Forever loop, your resting sprite will be more stable.

What is jumping in Scratch used for?

In game design, we create limitations and obstacles for our character, and the best games create meaningful conditions for both winning and losing that should be fair, easy to understand, and doable for most players. As jumping is, other than directional movement, the most important part of the majority of platformer games, you want your players to be able to predict how the limitation will work so they can develop skills and feel engaged with the game’s challenges, rather than ignoring the most powerful force in the universe.

Types of Scratch games that use jumping

Now that you can jump, you can create other touches in your game such as music, forward and backward movement, and maybe use a variety of shapes and sizes for your platforms or tricky puzzles. The fact is, if you want to make games, learning how to jump is an important skill for all these types of games.

  • Jumping game: Create a variety of floating platforms that generate as clones and move across the screen from right to left.
  • Shooting game: Instead of simply moving over obstacles, in a shooting game, characters will need to defend themselves, jump to avoid being hit, and potentially to fight back.
  • Adventure game: Most adventure games and some RPGs include the ability to jump, and many make jumping a changing variable that improves as a player progresses.
  • Racing game: Even in some racing games, such as the very popular Rocket League, do players have the ability to jump, making the game unpredictable compared to other car games.

Now make a Sprite Jump in Scratch

That’s all for our class on how to make a Sprite jump in Scratch. If you want you can check out Youtube tutorials for more help on this kind of project, as well as helpful tips and tricks to avoid bugs. Up next, learn how to make a clicker game in Scratch. You should also consider signing up for a free Scratch class at Create & Learn, where professional developers can guide your child through the process of designing their own games and apps. There's no risk in trying!

Written by Bryan Gordon, a Create & Learn instructor. After ten years of working as an English teacher, Bryan began studying Math and Computer Science over the past few years. Aside from writing and teaching, he likes cooking, gardening, playing guitar, and hanging out with his cats, Baguette and Wally.