Learn Phaser Physics
Learn how to incorporate physics into your Phaser games!
StartLearn Phaser: Physics
Lesson 1 of 1
- 1“I wonder if my character will make that jump…” - Every gamer ever. Figuring out the rules of a video game is a one of the joys of starting a new game. We wonder how fast our character can go, or …
- 2Let’s jump right in and make a sprite. We’ve made sprites before using the method this.add.sprite(), but this time around, we’re going to use this.physics.add.sprite() and have our sprite affected …
- 3In the previous exercise, we saw our sprite carried away by our game’s gravity. The reason we were able to implement gravity was through the use of a physics plugin which decides how GameObjects …
- 4We’re gonna get that player sprite to land on some steady ground. But first, we need to create a ground platform! This ground platform will not be affected by gravity but we want it to interact wit…
- 5We have a platform sprite, we have a player sprite, but they’re not interacting with each other! What’s missing? Remember, our physics plugin determines how GameObjects interact. The way to decide …
- 6Until we can telepathically instruct characters in games, we need physical controls to direct our player characters on how to move. One way we can implement controls is by using Phaser’s this.inp…
- 7At this point, we have a controllable player sprite, a platform, and a collider set up. Let’s make some enemies! Unlike the player sprite, we probably want multiple enemies to triumph over. And u…
- 8Currently, our game creates a few enemy sprites and stops. But we could create a loop to consistently create more enemies to make the game more challenging. To implement this loop we can call this….
- 9Our enemy sprites threaten to take over our game if we don’t remove them! We’re going to need to use Phaser’s .destroy() method to remove enemy sprites from our game. Let’s first take a second to…
- 10One thing we’re still missing from our game is a scoring system to motivate our players. We can store our score as property in the gameState object and increase it as the game progresses. To displa…
- 11It’s great to see our score increase, but it doesn’t mean much if there’s no way to lose. One common losing condition is when a player sprite collides with an enemy sprite. This means we need to in…
- 12Once a game ends, we should allow players to restart and try again! Phaser has a convenient method to solve this issue: this.scene.restart(). Like the method’s name implies, this.scene.restart(), …
What you'll create
Portfolio projects that showcase your new skills
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory