Warning: in_array() expects parameter 2 to be array, string given in /nfs/c08/h02/mnt/123925/domains/learn43.me/html/wp-content/themes/klein-child/content-badge.php on line 67

Warning: in_array() expects parameter 2 to be array, string given in /nfs/c08/h02/mnt/123925/domains/learn43.me/html/wp-content/themes/klein-child/content-badge.php on line 72

Warning: in_array() expects parameter 2 to be array, string given in /nfs/c08/h02/mnt/123925/domains/learn43.me/html/wp-content/themes/klein-child/content-badge.php on line 77

Warning: in_array() expects parameter 2 to be array, string given in /nfs/c08/h02/mnt/123925/domains/learn43.me/html/wp-content/themes/klein-child/content-badge.php on line 82
Default Badge

If you’re creating a Platform style game or a 2D side-scroller, you’ll want to add the ability for characters to Jump. And, of course, when a character jumps there should be Gravity to pull him back down.

Jumping and Gravity example

Jumping

What is Jumping? To jump is to move higher on the Y-axis.

Inside our Game loop we’ll add a Motion block to change y by. We’ll wrap this in an if block with a key pressed. 

Gravity

Gravity is just to fall or decrease on the Y-axis.

Creating a Ground (Optional)

In the example above, the character stops falling when he touches another sprite along the bottom of the screen.

We’ve created a new Sprite called ground and placed it alongside the bottom of the screen.

Also, we’ve wrapped our gravity inside of an If block. Gravity should only have an effect when the character is in the air or not touching the ground.