Multiplayer Pub in Babylon.js With Colyseus
June 6, 2024
June 6, 2024
Welcome to my interactive pub where you can explore my past projects in a unique and engaging way. On this site, you can walk around, either alone or with others, and check out my previous work.
Here's a glimpse of the backend code powering the multiplayer interactions:
TYPESCRIPTimport express from "express";import cors from "cors";import { createServer } from "http";import { Server } from "@colyseus/core";import { monitor } from "@colyseus/monitor";import { WebSocketTransport } from "@colyseus/ws-transport";import { GameRoom } from "./rooms/GameRoom";const port = Number(process.env.PORT || 8081);const app = express();const corsOptions = {origin: "https://balazspub.netlify.app",optionsSuccessStatus: 200,};app.use(cors(corsOptions));app.use(express.json());const gameServer = new Server({transport: new WebSocketTransport({server: createServer(app),}),});gameServer.define("GameRoom", GameRoom);gameServer.onShutdown(() => {console.log("Server is shutting down.");});app.use("/colyseus", monitor());gameServer.listen(port);
More details on how to set in the https://docs.colyseus.io/
Step into a world where past meets present, interact with the environment and others, and experience a new way to explore a portfolio.
Share this article
Start your day right with the daily newsletter that entertains and informs. Subscribe now for free!