Social Infrastructure At Scale

Cocos2d-x support for Nakama

Alim

Alim Jaffer

02 Apr 2019

Cocos2dx

We’ve had significant demand of late to provide an open-source client library for Cocos2d-x from the community to integrate with Nakama. I’m very pleased to announce a bespoke Cocos2d-x C++ client library. You can find it open-sourced on GitHub and our documentation here.

As with all Nakama client libraries, we ensure full compatibility with the feature set of Nakama in order to power games of all types — from realtime battlers to turn-based strategy style games. Some of the features include:


We’ve made the client library as intuitive as possible. Here are a few code snippets from our documentation to demonstrate:

Authentication:

1
2
3
4
5
6
7
8
9
10
11
12
13
auto loginFailedCallback = [](const NError& error)
{
};
auto loginSucceededCallback = [](NSessionPtr session)
{
};
std::string deviceId = unique device id;
client->authenticateDevice(
 deviceId,
 opt::nullopt,
 opt::nullopt,
 loginSucceededCallback,
 loginFailedCallback);

Websockets:

1
2
3
4
5
6
7
8
9
10
11
int port = 7350; // different port to the main API port
bool createStatus = true; // if the server should show the user as online to others.
// define realtime client in your class as NRtClientPtr rtClient;
rtClient = client->createRtClient(port);
// define listener in your class as NRtDefaultClientListener listener;
listener.setConnectCallback([]()
{
 // Socket connected
});
rtClient->setListener(&listener);
rtClient->connect(session, createStatus);

Send Requests:

1
2
3
4
5
6
7
auto successCallback = [](const NAccount& account)
{
 CCLOG(user id : %s, account.user.id.c_str());
 CCLOG(username: %s, account.user.username.c_str());
 CCLOG(wallet : %s, account.wallet.c_str());
};
client->getAccount(session, successCallback, errorCallback);

The server itself is fully open-source and we welcome any and all contributions! We have games running on Nakama that exceed over 30 billion API calls per month with some of our partner studios. The goal of Nakama has always been to democratise game development so that teams of any size, including indie developers or AAA studios can build their dream games without worrying about scalability and reliability on the backend.

Our team will be attending Quo Vadis in Berlin and Reboot Conference in Dubrovnik in April as well as PG Connects Seattle in May. If you’d like to meet up with us, feel free to reach out to us and we can arrange a time to meet.