)
Phaser and websockets
Learning websockets and Phaser
Johan
2025 | 1 | 30
I wanted to create a game in Phaser while also learning more about working with WebSockets. So, why not build a multiplayer game?
The UI is simple and made with Phaser. The game runs on a SvelteKit app, which makes it easy to display updates, such as success or error alerts, on top of the game.
My idea was to send the command that player 1 just made to the WebSocket server and then broadcast it to the game instances of the other players. A listener picks up these commands and applies them to local copies of the ball.
Well, it works—but not very well. Over time, the balls go out of sync. To fix this, I tried periodically syncing the positions, but that resulted in severe lag. Now, I’m experimenting with sending velocity updates instead to see if that improves things.
This is still a work in progress, but hopefully, I can make it at least somewhat playable so I can share it. Right now, though, this is just for the record.
Loading posts...