If you’re making a platformer, nine out of ten times, you’re going to need to create a jump function. There are certain cases where player-controlled jumping isn’t going to be implemented (see: NES Robocop, Bean’s Quest) but those seem to be more of the exception, than the rule.
Today we’re going to be talking about jumping mechanics in our game. We’re going to split this into two setup posts as well, so we can talk about the different methods of getting our player to jump, dependent on the way we want to use device controls.
We’re going to take a few minutes to set up our jump button(s), and to do that, we’re going to have to re-jigger our button layout.
The other jump option we will be using is the traditional four-way direction pad, and using the “Up” arrow. In the “shooting mechanics” tutorial we’ll go over what the “Down”arrow does, but right now it’s just going to chill out.
The prevDir holds the previous direction value, so that after the player hits the “ground”, movement still takes place.
Showing jumping logic by using transitions is a fun experiment, but no one is going to use this as a final solution in their game, so let’s look at how it would work with physics. First, we want to start the physics engine and create the “ground” to walk on.
TL;DR? Check the download link to see the full code and working project: