Creating a multiplayer browser game involves several components, from client-side development to server-side architecture. Here's a breakdown of key considerations and recommendations based on discussions from various developers.
Client-Side Development
For the client side, JavaScript is essential. If your game has graphical elements, using the HTML <canvas>
element can be beneficial [1:1]
[3:2]. For interface-driven games like Minesweeper, HTML/CSS might suffice. Libraries such as Phaser are recommended for beginners starting with web games
[3:4].
Server-Side Architecture
Implementing multiplayer functionality requires a solid understanding of server-client architecture. Many developers use Node.js for the server due to its non-blocking, event-driven nature which suits real-time applications well [5:5]. WebSockets are commonly used for real-time communication between the client and server
[3:2], ensuring low-latency interactions.
Game State Management
Managing game state is crucial in multiplayer games. Solutions like boardgame.io provide frameworks specifically designed for turn-based games, handling state management, game discovery, and more [3:1]. For fast-paced games, caching strategies using tools like Redis can enhance performance by reducing database queries during gameplay
[5:3].
Multiplayer Networking
Networking can be challenging, especially for beginners. Some developers recommend starting with single-player games before moving to multiplayer [3:4]. For those ready to dive into multiplayer, understanding concepts like peer-to-peer (P2P) versus dedicated servers is important. P2P can simplify development but may introduce cheating risks
[4:4].
Tools and Frameworks
Unity is a popular choice for developing multiplayer games due to its robust support for networking and available plugins [3:3]. However, it's noted that Unity might not be the easiest path for beginners unfamiliar with C# or its ecosystem
[5:8]. Exploring simpler solutions like Steam's relay services or other networking libraries can be advantageous
[5:7].
In conclusion, building a multiplayer browser game requires a blend of front-end and back-end skills, careful planning of game mechanics, and efficient state management. Starting with simpler projects and progressively incorporating multiplayer elements can provide a manageable learning curve.
Me and my buddy have made some projects using PHP before. We know HTML, CSS, PHP and a little javascript. What will I need to learn to make a small browser game that you can play multiplayer? We would like to avoid PHP for our next project. We would like to make a small minesweeper like game, but cooperative.
You'll definitely need a lot more JavaScript knowledge. If your game is graphically intensive you probably want to use Canvas. If it's more interface driven (like minesweeper) then using HTML/CSS as your interface would probably make more sense. You don't need much else beyond that.
Hey there, I'm a complete beginner when it comes to game development, but I have an idea of a game I would like to create. The game is very simplistic on the graphical side (text-based), but I have no idea of how to implement multiplayer to it. An example of a similar type of game would be TypeRacer. In this example I would be able to create an offline version of TypeRacer where I could test my own typing speed (By using Html/css/javascript). But I have no idea how to make it possible for, in example, 2 people to compete against eachother.
I hope the question was understandable and not too general.
I have written a small blog post on this before http://weigert.vsos.ethz.ch/2017/05/14/simple-online-multiplayer/. It has full source code. If you think what I do is suitable for your needs, feel free to PM me if you have more questions.
Thanks alot!
Hey so I have an idea for a multiplayer web game that would work similar to how websites like skribblio let you make lobbies and play simple games with friends, but I'm wondering what I would need to look up/learn to do this project. I know some basic JavaScript, but are there other things in particular I should be looking up on how to learn, or does anyone know how most of these multiplayer web games work? Any advice would be appreciated!
Probably the <canvas/> html element. And web sockets. I've never made anything like that before but I like the idea. Good luck my friend!
You can use Unity to make it. It supports JavaScript however I would recommend using C#. I'm sure the asset store already has a lot of easy plugins for multiplayer. But honestly, you should learn to make games first then go into multiplayer.
> I know some basic JavaScript
Start with a single player web game first then. Mutliplayer is not something that's suitable for a beginner. Phaser is a good start for web games.
Depending on your game's requirements, you might consider investigating boardgame.io. It is focused on turn-based board games, but that might be all you need. They discuss state management (including secrets), game discovery, turn processing, and other useful features.
I'm new to godot but have experience in web development.
I'm developing a simple tic-tac-toe game to learn the basics of multiplayer and matchmaking using the godot `ENetMultiplayerPeer`.
The architecture I'm thinking its this:
In general I will have something like this:
- `class Server` takes care of managing the matches.
- `class ServerPlayer` an entity that represents the player on the server side
- `class ClientPlayer` an entity that represents the player on the client side this is where the UI will exists.
The typical server-client architecture but I'm not sure if I'm overthinking this and there is a easier way of doing this but this its what makes sense to me but I have not experience making multiplayer games.
and where's the hard bit you wanna ask about?
I call the server-client architecture HARD because I don't know if that's a proper way here.
The other comment recommend making the player the server which it's more p2p
but not knowing if something is the right option has nothing to do with implementing the option being hard? i don't think i understand your question?
now about the choice of approach, i'd personally use the highlevel/scenetree multiplayer, where the server spawns one node per player, and they use RPCs (and a MultiplayerSynchronized board) to communicate. simply because it's less manual legwork of figuring out a dedicated communication protocol etc.
Was thinking same. Pretty standard, nothing too complex stuff here? :D
Just have one of the clients run the server ie p2p.
My recommendation is to follow the example for networking in the manual. After that you should have a better idea.
Yeah, I started like that, was simpler I but want to run a dedicated server that manages the matches by itself without UI, I'm not sure how to translate it to that use case without the server-client architecture.
And now the host can cheat however it wants, it's just a tic tac toe, but depending on the kind of game you make, but p2p will enable the at least one player to cheat easily.
It.'s better to learn the proper way with a simple game like tic ta toe.
For cooperative game where you know that players will know each others like phasmophobia, terraria, you don't really care.
But if there's anything competitive and matchmaking in your game you don't want one player to have any advantage over another client.
I’ve tried making a multiplayer game a few times before, but never with much success. This time though, everything’s actually working as expected—so I guess you could say this is my first real multiplayer programming project! I just want to make sure I’m not wasting my time here, heh. Since I only just started, I can still change things if needed.
I'm using Unity as a client, Node as the server and MongoDB for storage. The game is fast-paced and turn-based with real-time timers using a WebSocket connection.
Is this a common setup? What setup have you used? Is there a “better” way to do things, or anything I should know before diving in too deep? Any advice or wisdom would be really appreciated!
I'm making this game mostly for my friends, so I don't expect a large number of players—but you never know. People win the lottery all the time! ;)
Thank you.
[edit] spelling error :)
Keep in mind that even though MongoDB is relatively fast thanks to in-memory caching, it's still much slower than the memory of the Node server. Probably by several orders of magnitude. Especially when database and gameserver don't run on the same hardware. So you should consider to not query the database for every information during ongoing games. The database should only be used for "cold" data or data that is used very rarely.
OK, good to know, thank you! So far it is just storing user login information and their game stats. I am also using it to manage my tickets for matchmaking and private lobbies but maybe I can just use Node for that.
U might also need redis for best performance for your game. IF dont want to pay for it, then u need to cache all user data to node.js memory, which then limits your application to a single instance and prevents load balancing.
for exmaple if you game has chat, you want to have some ratelimiting so users cant send milliom messages per second. So every time the user sends chat, the backend server must check does he have "chat-tokens". And where you store this chat-tokens? in some cache, not in database. because db query per message is not good.
But also obiviously add the ratelimiting in clientside.
Good point. Thank you, I'll see if it is worth paying for. This is just a small user base project for now but you make a good argument.
Thanks again. I looked into this and yes, Redis makes a lot of sense and is not too expensive for what I'll be doing. As a proof of concept, I'll get the game working in Node for now and if there is more interest, beyond my friends, I'll add Redis into the mix. I appreciate it.
Totally valid setup! Unity + Node + MongoDB works well for turn-based games. Just watch for scalability stuff later—you're on the right track
Thank you! I appreciate that. Phew!
Well you sure ain't doing it the easy way.
Most people making multiplayer games just use something like netcode, mirror or fishnet for their networking stuff and Steam's relay (p2p free) which is pretty easy in the end
Man.... I never thought of Steam. I've tried using netcode and mirror in the past but those two specifically I ran into problems. I think the code ownership confused me, Like how the code is the client & server. Never used fishnet.
I guess I'm doing it this way because it's working.
I'll look into steams p2p. Thanks!
>I think the code ownership confused me, Like how the code is the client & server.
Totally ... I get why it's like this but it feels like there should be some simple architectural patterns/guidance on how to write code in this situation ... I've started splitting classes/objects into having client/server 'sides' to make it easier to understand WTF is happening where but ... still a lot to parse.
Is node a good option for building a multiplayer pong game (as in you can create a lobby and have someone join it from another computer)? I've seen concerns about node handling realtime multiplayer but was hoping for some more input on this.
research Websockets. That will allow you to do realtime state changes. I’ve used it to do chat apps and a “painting with friends” like app. It’s a steep learning curve if you have never touched sockets before. Once you get it working you never want to not use sockets for applicable stuff.
here is a good jumping off resource: https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers
edit: there are also packages/frameworks specifically for games using websockets but I don’t know any off the top of my head
I would go with webrtc for a game like pong since webrtc runs over UDP unlike websockets which is an upgraded TCP. It also comes with a learning curve though.
Yes, if u are proficient in node already. Given that pong isnt a very compute intensive game and doesnt have very complex gameplay calculations involved for each communication update it shouldnt overwhelm node. Game state updates in pong probably wouldnt require nanosecond sync either and shouldnt overwhelm nodes's i/o unless you have a massive player base. Latency is partly dependent on your infrstructure and concurrent playerbase count, shouldnt be a bottleneck at the outset. ofc dont try using node alone, use websockets for the broadcast and targeted communication.
Yes, Node.js is a good choice for a multiplayer Pong game. Pong is lightweight, so you don’t need ultra-low latency or complex networking.
Use WebSockets (via ws or socket.io ) to handle real-time communication. Node can easily manage lobbies, player inputs, and game state updates.
WebRTC isn’t necessary unless you're aiming for peer-to-peer with very low latency, which is overkill for a basic Pong.
If you're already familiar with Node, go for it. Just keep your update loop simple and avoid sending too much data too often.
Any resources on building a multiplayer game that I can export to the browser?
Yes, you can. Look at the photon library. Though, it can be a daunting task if you are a beginner.
I have some experience with photon (not a finished project, all I did was get some simple LAN games working with multiplayer)
I would like to create a simple 2D browser based card game with cross play with mobile app versions. People would have their own profile with play statistics.
What would be the ideal programming languages and technologies for this project?
I have some knowledge of HTML, CSS, PHP, Javascript and MySQL.
For android you can make simple app with webview component (embedded browser) in it that just displays your page. It's 10 lines of code.
You could achieve that quite easily with the languages you mentioned. Assuming you understand the basics of what you're trying to achieve (handling card logic, player turns, etc) the rest is just hooking it together to make it work.
Have a look into techniques such as polling, web sockets, events. Some good frameworks to learn would be Laravel (PHP) and React/Vue (JavaScript). Given that, you'd have everything you need to create your game. Happy to help answer any specifics you might have.
Perhaps also look into PWA's for the mobile aspect. That way you don't need to create mobile specific apps and get to reuse your web interface across all devices. Pushing updates is a lot easier too, it's as simple as updating the site — you avoid the app stores all together.
Hey everyone! I've been messing around with Godot for about 1–2 years, on and off, making small projects and eventually dropping them. Along the way, I’ve created some fun things and picked up a lot of knowledge. I’m definitely not an expert, but I’ve gotten pretty comfortable with it, and I felt like my recent project had some lessons worth sharing.
Over the past two weeks, I have been working on a project similar to an MMO built in Godot, and let me tell you, it is tough. There are so many moving parts that even a small change can ripple out and affect different areas of the codebase.
The core idea I love about MMOs is the persistent data. Everything is saved to a centralized database, so no matter where you log in, your progress follows you. It all gets consolidated into one place, creating a consistent experience across the entire game for everyone.
For my project, I set up the client flow like this: Login/Registration Scene → Main Menu → Join Game. The "Join Game" screen shows a list of available servers, and I can connect to one of my headless servers running on a DigitalOcean droplet. When I join, all my player data is there. Think of RuneScape’s world list where you can hop into any world and your character is always the same.
But multiplayer is where things get really tricky. You have to make sure data is properly synced across peers, and that the server has all the data it needs to run the game smoothly. And that is just the Godot side which is made a lot easier with Multiplayer Spawner and Synchronizer's to handle the bulk of the work. But there is an entirely separate layer with a hosted API that Godot makes calls to, which adds even more complexity.
For my project, I hosted a Ruby on Rails app. Whenever Godot needed data from the database, it would ping the API and return the necessary information.
Is this scalable? That is the question I am working through now. I can easily support 5–10 players on a server, but supporting hundreds would be an entirely different challenge.
One downside to this architecture is that it locks you into an MMO-style setup. What if I want to allow players to host and play on their own servers? That would definitely reduce server costs, but it also opens up new risks. Giving users access to host their own servers could expose the API and database to attacks.
All in all, it has been a really fun project, but scaling it and turning it into something that could be more official would be interesting to see.
Here’s a diagram of the architecture. I should note that it is not a perfect 1:1 representation. There are scenarios where the client can directly make calls to the API, which is not ideal. Ideally, the client would send a request to the Godot server, and the server would make the API call on the client's behalf. However, for simplicity and ease of development, I opted for this approach in my project.
Example Gameplay
- Showcases chat which heavily uses the multiplayer synchronizer to sync an array of the messages to each peer
- Showcases items getting added and removed from the player's inventory which are saved via calls to the API
That's a good first step. How is the inventory handled? Does the Clients just say they are dropping item slot x and the server is authoritative on what was in that inventory. Otherwise the client could say they dropped anything if the client was cheating. What about movements and actions? Do you ask the client to update the server on it's position or does the client simulate movement, but only sends inputs to the server, which runs the simulation and then corrects the client as needed?
Great questions!
Right now it’s basically the client just says they are dropping x item and sends a request to the api. But this needs to be cleaned up to where the client sends the request to the server and then the server validates if this is acceptable and sends it on behalf of the client.
As for movement (and interact) this one is handled by the multiplayer synchronizer node. So the client accepts the input for whichever player it has authority over and then the position is synced across the connected peers. But that is an excellent point on this one. The server probably should validate the movement from the client to make sure it’s a valid movement.
Great post, For scaling you probably want to look into containerizing your API server, and using digital oceans database clustering etc for Postgres.
Exactly! I’m wanting to make a ci pipeline that would put the server (and my api) into a slim Debian container that I would then be able to load either and as many as I want onto a single machine that way I’d have quite a bit to pick from.
I’ll have to read up on digital oceans db clustering. Right now the api is in heroku with the Postgres attached to it so I can easily up the scale there if needed but I would like to tune it better.
So I've actually been looking for some ideas for this. From the crazy (find a game with an existing private server , write a client for it in godot) to lots of other stuff.
Haven't had a chance to try it but spacetimedb and it's associated godot plugin look like a good way to go. So for example, the api would say "drop an item" send an sql request to the server, and the server would run the code, and validate if that's allowed, and everyone syncs to that server.
Interesting! Yeah that looks like a very cool tool. For my architecture it looks like it would replace the top two pieces of my diagram as this looks to roll them up into one.
I see a lot of mentions of speed with SpacetimeDb so I wonder how fast my own implementation is compared to it
I made this game during the UK lockdown. I still continue to maintain it with updates.
This game is a simple MMO web browser game inspired by old flash games. It's a fun and friendly place to hang out. Chat with other hedgehogs. You can explore different areas such as the Cafe or the Cave.
You can collect coins and spend them in the shop to buy items for your character. Earn coins by playing mini-games. This project is still experimental.
If you don't mind me asking, what does the architecture look like for something like this?
I'm not using any typical game engine, it's all mostly custom with the help of certain web libraries and frameworks. I also want the game to be accessible on mobile, tablet and desktop screens which I don't think game engines typically make this easy, however I might be wrong as I am not that experienced with using game engines...
I use a JamStack serverless approach for the main site. The game client uses PixiJS to render the graphics and I use ReactJS for the UI. For the game server I use NodeJS with SocketIo. If I need to scale the game I would be able to hook multiple backend NodeJS servers to handle that. So players would select the server to join etc. For the time being it's adequate enough with just one server while I work on core gameplay features.
Very cool and nostalgic, only thing I would recommend is to make this available on mobile as most web based games of the flash era have been replaced. Not sure exactly which tool set you’re using but there are frameworks that allow you to natively port them to android/iOS or just as webpages that appear as apps, so if it’s coded with JavaScript then it should be fairly easy to port.
>Hello, thank you for the feedback! The game is responsive and you can play it on mobile in the web browser right now without having to download anything. Visit the site on your mobile browser and it should work.
I have thought about submitting an app version to the app stores etc but for now, while I'm in the experimental development stages I don't think I am at that stage yet. Also on IOS (I haven't got an android to test), you can "Add to Home screen" on Safari and the game will feel somewhat native without seeing the Safari toolbars etc and the game will appear even more in fullscreen. Perhaps give it a try and let me know what you think?
looks like club penguin
was about to say that.
How to code a multiplayer browser game?
Key Considerations for Coding a Multiplayer Browser Game
Choose a Game Type: Decide on the genre (e.g., action, strategy, RPG) and mechanics (turn-based, real-time) of your game. This will guide your design and technology choices.
Select a Technology Stack:
Game Design and Prototyping:
Networking:
User Authentication:
Testing:
Deployment:
Post-Launch Support:
Recommendation: Start with a simple game concept to learn the basics of multiplayer game development. Consider using game engines like Unity with WebGL support or frameworks like Phaser for 2D games, as they can simplify many aspects of game development.
Get more comprehensive results summarized by our most cutting edge AI model. Plus deep Youtube search.