Can I make a multiplayer Phaser game using Lance?
Asked Answered
R

1

4

How do I take an existing Phaser game and make it multiplayer?

Can I use the Lance library for this purpose? Both libraries control their own game objects so I don't know how to use the two frameworks together in the same game.

Rossanarosse answered 20/5, 2017 at 10:56 Comment(0)
R
11

Disclaimer: I am one of the co-creators of Lance

Unfortunately, Phaser's 2.* architecture makes it hard to pair with Lance to make Realtime Javascript Multiplayer games.

The issue is that Phaser makes a lot of assumptions that don't hold for a multiplayer setting. For example, the rendering and game loop are tied together. The server, obviously doesn't need to render anything.

Phaser also assumes the existence of the DOM and the window object which also don't exist on the server. In addition, all of the data structures that hold the world game state objects, sprites, etc' are saved on an extended instances PIXI objects which don't make sense in a Server context. These limitations and tight-coupling aren't compatible with Lance's modular approach.

It is entirely possible to run Phaser on the server using libraries that emulate DOM and Canvas like JSDOM and Node Canvas however it does mean that there's a significant performance degradation by running PIXI on the server, and you also still have the problem of syncing PIXI data structures to contend with.

The good news is that Phaser 3.0 is an ongoing, complete rewrite of Phaser 2.0 in a much more modular approach will hopefully make it much easier to integrate with Lance. We have plans to make this integration easier ourselves in the near future.

Recovery answered 20/5, 2017 at 11:21 Comment(3)
Hey, what do you think about Phaser 3? I was using Pomelo before but want to try Lance instead. I don't need lag compensation and some other major Lance features but it looks much more friendly than Pomelo. I would use it to handle only backend loop (calculations and other stuff), frontend game loop will live on it's own and only recive/send data via sockets. Am i overthinking it or should it work fine with Phaser? By 'fine' i mean - doesn't take months to overtake possible issues with Lance <-> Phaser integration.Snatch
Are you sure you don't need lag compensation? Is your game turn based? Otherwise you always need some sort of lag handling. I haven't had a chance to look at Phaser 3 just yet, so I can't tell you how easy the integration but I'm planning to soonRecovery
Yeah i'm sure. Backend will handle things like market or random events that will be pushed to player and there's no problem with 10s or even 1 minute delay because there will not be real-time interaction between players. So that's not the case at this time, maybe in future. I'm looking mainly for replacement for Pomelo which takes a lot of time due to the lack of good documentation and the community. It's powerful but it's hard to use. That's why I'm thinking about using Lance purely backend at this point. Anyway, thanks for the answer and let me know when you take a closer look at Phaser 3.Snatch

© 2022 - 2024 — McMap. All rights reserved.