Sprite Jumping for Beginners
This article will teach beginner Scratchers how to make sprites jump in Scratch! The code we show below is the easiest way to make sprites jump and look nice while jumping.
To follow along, make sure to first do these steps:
- Make an account at the Scratch website.
- Create a new Scratch project, and use the sprite button to add in new sprites.
- Follow our how to make a Scratch game step-by-step tutorial if you need help getting started.
- Practice programming basic left and right sprite movement.
After these steps, jumping is a natural next step for Scratchers! Learning simple scripts like this one is the perfect introduction to computer science, and will make learning other programming languages much more intuitive.
Once you've mastered jumping basics, you can move onto our upcoming “How to Make Sprites Jump Realistically" tutorial, coming soon!
What is Jumping?
In real life, jumping is the act of using your legs and feet to propel yourself into the air. That probably isn’t news to anyone, though! While everyone knows how to jump, it’s probably not something that you do very frequently.
Aside from playing sports or exercising, we can go almost our entire lives without ever needing to jump. However, in the world of video games, jumping is much more important!
Why is Jumping Important in Games?
In video games and Scratch games, character jumping is as important as being able to walk. Many video games are configured so that when the player presses a key on their keyboard, their character will jump very high.
This useful mechanic improves the quality of video games in many different ways. Adding the ability to jump into your game will make your game:
- More interactive
- More complex
- More challenging
- More fun to play
Adding jumping into games also allows for the creation of obstacles and other pitfalls that the player has to jump to avoid. These new mechanics in turn make your game even more fun and challenging! Many extremely popular games have utilized jumping to do exactly that.
Applications of Jumping
Jumping is such an important game mechanic that it is used in many of the most popular games of all time. While it looks slightly different in every game, pretty much everyone has played a game that requires you to jump.
Here's some of the most iconic types of games that include jumping mechanics:
|Platformer games||Platformer games require the player to use jumping in order to pass obstacles and complete levels — something Scratch is perfect for. This category includes massive game franchises Super Mario Brothers and Sonic.|
Sandbox games let the player to do pretty much anything that they want to. They are open world, and let the player break and place items or blocks.
While jumping isn’t as important as in platformer games, it's still one of the most useful and important mechanics in sandbox games like Minecraft and Terraria.
|…And just about everything else!||Jumping also makes an appearance in almost every other type of game that you can think of. Even games like Flappy Bird have a jump mechanic, although they’re not what we would traditionally think of as “jumping.”|
While many of the games we mentioned are far too advanced for beginners (we also cover more advanced games in our Scratch Level 2 course, Scratch lets us easily code many simple games with jumping.
To begin with, try to add a jump mechanic into a game you’ve created already. Something like the game we made in our how to make a game step-by-step article would be a great place to start!
How to Make a Simple Jump Mechanic
To learn how to make a sprite jump, we first have to understand how to transform our knowledge of “jumping” into computer code that the Scratch programming language can understand.
We can think of jumping as another form of movement in Scratch, just like moving left and right when the left and right arrow keys are pressed. Games usually use the “up” or “spacebar” keys to jump. For our project, we will say that our character will jump when the player presses “spacebar.”
Here’s the secret to programming a jump:
- When our character jumps, he starts by moving up. However high he jumps, he must always fall back down the same amount.
This is pretty intuitive if you think about it — if you jump 3 feet into the air, you're always going to fall down 3 feet and land on the ground. This means that whenever we tell our sprite to move up, we must then tell it to move down by the same amount.
We’ll be using a new block to tell our character to move up/down vertically. This is the
change y block. Whenever it runs, it tells our character to change its Y position by the specified amount.
If you recall, a sprite’s Y position determines its vertical position on the screen. A Y coordinate is usually paired with an X coordinate (that determines horizontal position) in order to describe exactly where a sprite is on our screen.
Try experimenting: Other blocks that change a sprite’s X position exist as well, such as the
change xblock. What would happen if you swapped the
change yblocks in this script with
The Simplest Possible Jump
This is the simplest possible way to make sprites jump on demand. It’s pretty short, with only 3 code blocks run when the spacebar key is pressed.
Here’s a simple explanation of how the code works:
- First, we use a
change yblock to tell the sprite to jump 100 pixels up into the air.
- Once our sprite is mid-air, we tell it to
wait 1 secondin order to make sure we see it there.
- Finally, we use another
change yblock to make our sprite fall back down to where it started.
Notice that since we tell our sprite to go up 100 pixels, we then have to tell it to go back down by the same amount. This is the key to making sure the sprite falls and always ends up back at the same spot.
Here’s a good rule of thumb for this: If you add together the values of all your
change y blocks, they should add to zero!
Experiment: Modify the values in this code to see what happens. For example, what happens when you
change yby 200 instead of 100?
Try this code out for yourself, or experiment by playing our sample Scratch jumping project!
A Better Jump
While our first method of jumping technically qualifies as a “jump,” it doesn’t really look like what we imagine jumping to be. Right now, the character simply teleports upwards, waits, then teleports back down. Let’s make our sprite move continuously to make the jump look more realistic.
This code is super easy to create, and is the jumping method that we teach in introductory Scratch courses. The way it works is very similar to the previous code, except that it uses
repeat blocks to make the jump look smoother.
What's the difference? Both this method and the previous one move the sprite upwards 100 pixels total. While the first method makes the sprite move up 100 pixels all at once, this new method uses repeats to make the sprite move in intervals of 10 at a time.
This slows down the sprite and lets us see it move, making the jump look much more realistic. Because of this, we no longer need a
wait block to slow down our code.
This new code looks much better, but you might notice that we're not able to move while jumping. Since this script uses a simple
when Spacebar pressed event listener, we can’t use it at the same time as other event listeners like
when Right arrow key pressed.
If we want to be able to move and jump at the same time, we can change our code to look like the following script:
This is pretty much the same code, but it uses an
If spacebar pressed conditional instead of a
when spacebar pressed event listener. Additionally, we also put the code inside of a
forever loop to ensure that it always runs properly.
Since we no longer have key-dependent event listeners, our cat sprite can move and jump simultaneously!
Experiment: You can use the same method of a “forever loop” and
if < key > pressedto create smooth left and right movement! See if you can figure out how to do so, and add it to your game.
Try out this method of jumping, or reference our sample sprite jumping project with this code.
Nice job coding a jumping mechanism! While this method of jumping looks and feels much better, it’s still not perfect. This jump is a “linear” style of movement, where the sprite’s motion is constant when moving up and back down.
This method is great for newer Scratchers, but there are more complicated ways of making character jump realistically. These advanced methods use realistic gravity in Scratch, and make for some truly amazing projects. Stay tuned for our articles on advanced Scratch game coding!
Check out these next Scratch tutorials you should try: (coming soon!)
- How to make sprites jump realistically (advanced jumping)
- How to make gravity in Scratch
- How to make your sprite move smoothly
- How to make a sprite move in Scratch
- How to Make a Game in Scratch with Levels (beginners)
Keep Learning: Scratch Coding Classes for Kids
For structured Scratch learning, Juni Learning offers project-based Scratch Courses for students 8-11 to get started with coding. Our Scratch curriculum prepares students with full mastery of the Scratch environment, and prepares them to advance into coding with more advanced, text-based languages like Python.
- Game Superstar (Scratch Level 1): introduces computer science fundamentals such and teaches students how to build and design their own Scratch games.
- Game Master (Scratch Level 2): covers more complex concepts like nested loops, complex conditionals, cloning and more in preparation for learning more advanced coding languages.
Read more about our coding classes for kids, or speak with our Advisor Team to learn which course is best for your student’s coding journey by calling (650) 263-4306 or emailing email@example.com.