MelonJS – a fresh and lightweight JavaScript game engine
github.com
github.com
More here https://www.melongaming.com/en/Games
Maybe you can also integrate the accelerometer on phones for a compact and more fun example?
I noticed this in the game you linked as well.
Web libraries (react, etc) are very advanced and it'd be incredibly hard for a js game engine to match them for UI
I use react in my game platform bloxd.io - which I work full time on - and I couldn't be happier
Would you be able to give any advice on netcode/multiplayer solutions? I like working with low level rendering libraries (canvas, Kha/Haxe) but I am wondering if it is better to use an engine versus libraries, or even just rolling my own solution with web sockets?
For web native rendering pixijs is good for 2d (and phaser is good also a good entry level). For 3d theres threejs/babylonjs.
There's also unity, which some browser games use but it has downsides on web (large build sizes for one)
None of the networking solutions will give you unreal engine netcode developer productivity (and that includes ones for unity). I use colyseus, it doesnt solve everything but will save you some work
Re saturation, it definitely depends on the genre, web is its own market. What type of game are you thinking of making?
I’ve heard of Colyseus and it’s good to know that it is a viable solution. I am keen to try out the Haxe library.
I’ve got some loose ideas for some 2D semi-realtime games. No solid ideas yet but I want to experiment.
My most recent web game uses both standard DOM and Canvas for rendering different parts of the UI and text, and both look equally good to me. You do have to have set up the Canvas rendering correctly, especially for sharper displays like Apple Retina displays with higher pixel densities, but when done properly it looks very sharp and has no issue IMO.
This isn't inherit to JS game engines, but I will say text quality is not usually something that game devs focus on unless text is important to their particular game.
Here's an example of a workaround to render more crisp text https://github.com/danman113/gfx-utils/blob/main/src/canvas/...
I think canvas kept the "1 px is 1/96th an inch as reported by the browser not a display pixel" convention primarily for consistency as that's how the px unit worked on everything else in the browser.
I tried a game engine some time ago (sadly I forget what it was called) but it bundled the entire library as soon as you tried to do the basic thing. If I recall it was over 1MB. These days JS transpires have incredible functionality for slimming down payload sizes and it's awesome to see more and more libraries making use of it.
I've tried building a few real-time games with different implementations of these HTML5/JS game engines, but I always hit a wall when trying to add multiplayer capabilities.
The main issues I've found is there's never a way to get a "universal" X/Y/Z position for an object that can be accurately stored in a server that syncs with the position for players. It always tends to be ever so slightly off in a way that desyncs over time, making a stutter when the server has to force a resync. This is then compounded with collision detection physics, which these engines never do in a "standard"/specified way, requiring me to reimplement their physics server side, which inevitably causes occasional game breaks from the inconsistencies - going through walls, or total desync.
Anybody have any suggestions/solutions/recommendations?
There’s a number of approaches. One approach is that you need to make your local simulation deterministic so that every client can do their own work and simply agree that they’re on the same page. You then send events, not state, in turns.
Saving state in a hashable structure can make it easy to check if all clients agree.
Decoupling the local sim from the multiplayer events can make the game feel smooth, even if at times there’s rubber banding.
This is such a good read: https://www.gamedeveloper.com/programming/1500-archers-on-a-...
I think my backend and overall strategy are good, sending events rather than state, deterministic simulation, event buffering, client prediction, etc, ultimately my issues arise on the client side when using these frameworks, I haven't found one that considers how a game server operates, so it ends up requiring a good deal of hacking to inject server messages into the game state at the right places, and ultimately the math is always a little bit off, rounding issues add up, rubber banding appears, etc. I guess I could write my own engine from the ground up with a backend in mind, but I don't have the free time to make the engine and the client and the server and the actual game, so I was hoping that maybe Melon2 would have considered my use case.
Also, a piece of advice I once heard that resonated with me: you either make a game engine or a game. Never both.
There are race conditions all over and I'd imagine you'd need to have a hash of current and next positions to prevent conflicts.
In this situation you can stream movement waypoints from remote clients and lerp between those waypoints locally to simulate movement. If latency is low enough you can make predictions about the next waypoint and it won't look bad when you're wrong.
If you're PvE, you're done. Nobody needs to know precisely where their teammate is as long as the game feels fair. (The AI players on the other side won't complain.)
In PvP the opponent will complain, and they're also a customer, so you have to do something about it. This is an entire technical discipline within gamedev if you want both accuracy and player freedom.
Don't be afraid to let technical constraints guide your design. If you don't want to spend your life building remote physics validation or latency-aware consensus algorithms, make your players interact with the world via clicking so you always know exactly where they wanna go next. One of the super powers of being a programmer + designer combo is making trades across disciplines to maximize your output.
The biggest source of these inconsistencies is Math.sqrt(). You need to implement deterministic version of sqrt() and that should fix 99% of your issues. Hit me up if you need some additional pointers.
I'm using this sqrt implementation (found it long time ago on some old action script blog, this link is not the original source). It's plenty fast, accurate and fully deterministic. I successfully implemented it in my multiplayer gta2 clone in javascript.
I've been building a MOBA, using Photon Engine for the networking. It's a framework that handles everything you just described, using different paradigms depending on your preference.
The one I'm using, called "Photon Fusion", runs the entire game on the server to replicate all the game logic and physics that the client side has, as you described. However, it takes care of desync issues by using some clever interpolation and client side prediction with tick-based simulation, while keeping the server as the state authority with extremely optimized compression of communication to support lower bandwidth.
https://www.amazon.com/Multiplayer-Game-Programming-Architec...
I only have experience with 2d (so it might not be useful to you, but perhaps will others), where typically it's a worse experience for the player to have CSP (client side prediction) at-least in a fast paced game, as for example a player behind a wall can more clearly see something missed them, yet they still got hit.
The way I do things (and I've seen is common across other "io" games), is "CSP" only for particular actions (such as your own rotation, or swinging your own weapon), but otherwise just let the client move in step with the server in terms of any physics entities etc.
It's using phaser on the server in this instance (which I recently ripped out, and moved to just using matter)
It's pretty ugly code, but the foundations are there, maybe it's a starting point or of some use!
By the sounds of things you’re sending positions updates and broadcasting them from the server. If that’s the case some bog standard interpolation should just work. If you’re seeing divergence then you’re probably running code with a non-deterministic result on the different machines. Typically speaking you want to work out who ‘owns’ each part of the simulation and make sure anything you do elsewhere converges back to that.
This is cool too, though.
To me, it has previously felt clunky to use older (and more mature, sure!) toolkits when building a one-day game just for fun.
The line-of-sight demo appears to be buggy on Firefox, however: A box behind a closer box that blocks the view is marked as red.
There's no mention of networking so i guess multiplayer is not inside its current scope?
What is the state of Cordova these days for a typical reactive webapp ?
If you're going from web dev to game devs as a hobby or just fun side thing, then a JS engine like Melon is a good way to dive in and start creating something people can enjoy without serious investment.
I've also played around with Unity a bit but haven't released anything or finished any project. If I wanted to transition to full time game dev I would probably start learning Unreal or Godot as an engine for major projects... or focus on making browser games, maybe with a JS game engine like Melon or Phaser, or continue to roll my own JS games. The big engines like Unity can compile to web but it's a subpar experience and I wouldn't use it if my main target was in browser.
Web devs like us will have some advantages in already being exposed to some of the networking and stuff related to multiplayer, auth, leaderboards, etc.
Almost no jobs. However, if you can find them they pay much better than Unity/Unreal jobs because html game dev is such a rare skill. The decision tree you need to follow to end up as a html game specialist is so fraught with distractions almost no one ends up there.
But, for those who do I recommend Phaser.