Well, this is gamedev! It turns out I didn’t need to add the sync to the paddle. Flowlab automatically handles that. Quick video above of two browsers connected and playing Multiplayer!
Screenshot below of the updated paddle logic.
With multiplayer, you can make ‘Player’ objects and ‘Shared’ objects. When you make an object a ‘Player’ object when someone new joins the game it duplicates the object and synchronises the game with the new joining player. As you can imagine, there are only 2 players needed for Zong Pong, so how do you get around that? When I set each paddle to ‘Player’ objects when both plays joined the game there were 4 paddles appearing!
Time to think again!
A quick noodle with Grazer at Flowlab and now the paddles in the game are ‘Shared’ objects so they do not get duplicated when a new player joins the game. However, this means that only one player will see their paddle move as we’re now missing the ‘Player’ objects. ‘Player’ objects ger local keypresses and distribute them to all the other connections.
Do you see the red block in the screenshot below? That’s now a ‘Player’ object. Inside the object is the paddle logic which sends messages to the paddle in the game. As there is only one it duplicates to 2 and both players can see both paddles moving.
Flowlab Multiplayer is new to me, but it’s super cool and I can see great potential. I still need to iron out synchronising the scores. Almost there!
Here’s the link to Zong Pong again.