Beginner’s Guide to Boardgame.io (Part 2): Local Multiplayer

Jimmy Cheung
1 min readJun 1, 2020

Now that we’ve figured out how to create a barebones TicTacToe app, it’s time to level up to the next step — multiplayer. Multiplayer is one of the features that boardgame.io allows you to abstract away: you will be writing very little code to add multiplayer to your webapp. A lot of the code to implement the nitty gritty of multiplayer has already been written! You can even review it in Boardgame.io’s Github Repo here.

So how do you actually add local multiplayer to a boardgame.io app?

It’s actually quite simple! Since Boardgame.io abstracts so much away, it’s as simple as setting certain property names/keys when calling on the BoardGame.io client.

First, here is the previous client code from the barebones TicTacToe app:

In the Client call, you can add a key/property name of “multiplayer: “ in order to enable multiplayer.

Then, you have several options for multiplayer. You can add Local multiplayer by importing the Local functions from ‘boardgame.io/multiplayer:

Local Multiplayer will allow you to initialize the Client with multiple playerIds. Then, you can display both clients with their individual TicTacToeBoards. In your TicTacToe game definition, you can code different rules to regulate multiplayer play.

Conclusion

Boardgame.io setup is super easy for basic applications. Once you have your rules coded, complex features such as multiplayer can be implemented in an instant. In addition to local multiplayer, you can also implement remote multiplayer through a server, which I will explore in a future article.

Source

https://boardgame.io/documentation/#/multiplayer

--

--