Play multiplayer with facebook friends

Hi there, I’m making a game on Cocos2dx for both android and iOS. In my game I’m making a social multiplayer level in which the user can connect to any of his facebook friend and then the game will give both of them an identical challenge and whoever solves it with the highest scores wins. I would also like to maintain a scoreboard of all the friends. Is this possible with cocos2d-x. Any suggestions on how it can be done?

There isn’t built in functionality to do this. I think you would need to have your game communicate with a central server someplace to store this data. Or find a way to do it peer based.

Isn’t there anything that facebook provides that would make this easier? facebook’s developer page mostly talks about status sharing and stuff. What about sending some sort of information from one user to another?

Well that is peer based. I’m not sure what Facebook has mechanisms for. There isn’t a built in function in cocos2d-x that you can use. You will need to write it. There are plenty of multi-player sdks out there though that you could integrate. People here have surely done it.

Not entirely sure myself, and I have no idea about integrating Facebook into a Cocos app, but I suspect Facebook only provides the ability to identify people and to access their Facebook data that you have requested permission for.

The main advantage of using Facebook is probably that you can let Facebook handle authentication (you won’t necessarily need your players to create an account specifically for your app) and, of course, allowing your players to post stuff directly to their Facebook walls.

Beyond that, I imagine you will have to handle everything else yourself, including multiplayer communication and storing player data, e.g. character names and progression.

First step, you will need a web server your game can connect to and communicate with. Exactly how to do this with Cocos I am unsure, but it will be possible.

If both players don’t need to play at the same time, I’d do it like this:

  1. The server would pick a random challenge, assign both people to it and store it in a database under “Current Challenges”.
  2. Whenever a player connects, the app would request the list of current and previous challenges for this specific player. This would be used to display challenges the player has available and the results of at least the most recent challenges.
  3. When the player completes the challenge, the app would send the time to server which would store it.
  4. When both players have completed the challenge, the server would choose move the data from “Current Challenges” to “Previous Challenges”, so when the app next requests the previous games, it will get this data.

That’s a simplistic explanation, but that’s how I would get started on it. If you need both players to take the challenge at the same time, you’d have to handle peer-to-peer communication. Cocos2d-JS might have websockets built in, which I believe could be used to handle this. But all this is my best guess on the subject.