Skip to content

alidbc/phaser3-multiplayer-with-physics

 
 

Repository files navigation


header
Phaser 3 - Real-Time Multiplayer example with Physics

A Real-Time Multiplayer example using Phaser 3 with Physics (MatterJS and Arcade) on a NodeJS server with Express and Socket.io

GitHub last commit


Play It

This example is running on NodeJS on Heroku (Free Dyno in Europe) which causes the example sometimes to take about 1 minute to load.

  • Play it here - phaser3-multiplayer-example
    It works best if your latency is below 100ms, which should the case if you are located in Europe.

Key Features

  • The physics is entirely calculated on the Server
  • Automatically manages Rooms (new Phaser instances)
  • Physics debugging version
  • A nice Stats page

Video

Watch it on YouTube

thumbnail

Matter Physics vs Arcade Physics

This example includes 2 different games. One with MatterJS and the other with Arcade. The MatterJS game has only one level. The Arcade one is a simple platformer game with 3 levels.

So in total, you can play 4 different levels. For each level, the server creates a new room, which creates a new Phaser instance, which are completely isolated from each other. There can be up to 4 players per room.

Structure

├── src
│   ├── client  # Contains all the code the client will need
│   ├── physics # This is for debugging the physics (Arcade and MatterJS)
│   ├── server  # Contains the code running on the NodeJS server
│   └── stats   # The stats page will show useful information about the server

How To Use

To clone and run this template, you'll need Git and Node.js (which comes with npm) installed on your computer.

You also need to install some additional packages since this example uses Node-Canvas. See here.

From your command line:

# Clone this repository
$ git clone --depth 1 https://github.com/yandeu/phaser3-multiplayer-with-physics.git phaser3-example

# Go into the repository
$ cd phaser3-example

# Install dependencies
$ npm install

# Start the local development server (on port 3000)
$ npm run dev

# To publish a production build using docker use docker:publish
# This needs docker and docker-compose to be installed on your machine
$ npm run docker:publish

Other Multiplayer Examples

Looking for a simpler multiplayer example? Take a look at Phaser 3 - Multiplayer Game Example.

License

The MIT License (MIT) 2019 - Yannick Deubel. Please have a look at the LICENSE for more details.

About

Phaser 3 - Real-Time Multiplayer example with Physics (MatterJS and Arcade)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 91.1%
  • JavaScript 6.4%
  • HTML 2.2%
  • Dockerfile 0.3%