Programming Games for Android

Programming Games for Android 29: Continuous jump

42 videos

238 minutes

We will make the system jumps that should have our game, which is like having the Geometry Dash. When the player touches the screen the character must jump, obviously. That we have already done in the past. In fact, we have seen that when we make a justTouched we can make it jump. But then, we can do that if when the player hits the ground the screen is pressed the player must jump again. That is, the player does not jump

by its own means forever. When there is a collision should check if the screen is touched by the player, it must return to jump again. What I will do is change the name of this variable debeSaltar, and as simple as whether to jump ... jump. Now we will see in what situations we want to jump. For example, let's create a new variable. I like getting out of hand is the subject of the variables. The'll call joeSaltando,

this will be jumping when you create the JoeEntity. This variable will indicate whether it is jumping or not. And it is simple: If a collision occurs, it will be because joeSaltando is false, because it will no longer jumping. Although, now that I think about this I can not do so, but what I do ... well. Let's make a contact also finished. When finished contact between Joe and soil, it is because Joe is jumping now necessarily.

What finally going to do is this: if the screen is touched and is not pre jumping, then a jump is applied. And what we will do, once we see this works it is that if when I collided with the game the screen is touched, jump again without any problem. This falls, jumps, and you're done. You see I can not make jumps in the air. It is necessary that Joe is not jumping. Let's see how they do now that double jump or triple jump,

ie that hit the ground continue jumping. If in this case the screen is still touched, what we do is to continue to have to jump. Obviously this will also have to write down. In this case, though now you do not see it, I will keep the mouse without releasing it. And now stop jumping. If loose, no longer. If I hit, now. This is a more realistic system like making Geometry Dash.

I carry this to something more comfortable to work to not have variables everywhere, because this is already a mess. But it's more or less what we have to do, always work with flags because of this limitation ContactListener not let us do jumps from the same contact. It is not a limitation, is simply that it works. We need to detect when it is jumping not make a double jump in the air,

which may be fine, but in this case I do not care. As if to jump the jumps are applied in a more controlled form of the program, as it can be with the rest of the physical efforts. At the moment, this is an intuitive way to jump.

To find new courses, subscribe. There will be no spam, promised :)

About the Author

foto de jotajotavm
José Javier Villena

Biography: Analyst-Programmer in different languages. Tutor PREMIUM platforms recognized worldwide as CodigoFacilito. Editor Cristalab articles. My YouTube Channel is sponsored by the ANAYA and LaTostadora publisher. I like to explain in detail and give several examples for the avoidance of doubt.