Trusted answers to developer questions

How to make a simple platformer using JavaScript

Get the Learn to Code Starter Pack

Break into tech with the logic & computer science skills you’d learn in a bootcamp or university — at a fraction of the cost. Educative's hand-on curriculum is perfect for new learners hoping to launch a career.

A platformer is a game in which a character moves around to avoid obstacles and jump onto suspended platforms.

Let’s create a simple platformer using JavaScript and minimal HTML – the arrow keys will be used to move the character around.

1. Creating the player and platforms on a canvas

2. Adding the “move left and right” functionality

Click anywhere in the blue area, and use the left and right arrow ke​ys to move the character around:

3. Adding the jump functionality

Click anywhere in the blue area and use the up-arrow key to make the character jump.

The above code can be extended to add more platforms, bonuses, levels, and to check for more types of collisions.

RELATED TAGS

platformer
javascript
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?