Colyseus Walkthrough

What is Colyseus?

Colyseus is a networking framework that allow game developers to easily turn their creations into networked games, allowing them to implement multiplayer and to extend functionalities beyond the engine.
It is an open-source tool that supports many client-side technologies, such as Unity, Phaser, Construct and many more. It's server-side code is made of TypeScript, a strongly typed programming language that builds on JavaScript, the web standard programming language.

Why Colyseus?

While there are many other networking tools, specially for the Unity Engine, Colyseus stands out as the easiest framework to be used capable of externalizing the server-side code outside of the client-side technology.
Very few lines of code are necessary to get it working in a single-player networked game, and not much more to get the multiplayer implemented.

How does it works (server-side)?

Each "instance" of Colyseus represents a single server for a game. Within this server, we can have and handle many Rooms of different types. Think of how an FPS multiplayer game works: there are many server across the globe to better handle lag, and in each server, there are many rooms to host matches simultaneously. Since there are many game modes available, such as Deathmatch or Capture the Flag, we will have different room types for each of these.
Another major component to this logic are the states. These states are where all the shared networked data is stored. For example, a room state has variables that holds how many players have joined it and how many points each teams has, or a player state might have the player name and player color.
Diving into Colyseus scripts, it consists of 4 main files: index.ts, arena.config.ts, "MyRoom.ts" and "State.ts". These last two scripts are customizable by the developer and could have any name, fitting the game's context. There can also be multiple different scripts of the same type, such as "GameRoom" and "ChatRoom" or "RoomState" and "GameState", bound again to how the game is organized.

How does it works (client-side)?

The client-side logic of Colyseus will vary depending on the technology your game will be using. Our tutorial, available on the next page, will show the bare minimum on the Unity Engine to get everything working.