Cocos2d-x

Quick Start

Download the Latest Version

Application of Navergame SDK to the Pre-existing Project

This guideline has been written in respect to version 3.17.2 of Cocos2d-x.

1. Plugin Configuration

  • The files needed for the SDK are contained in the Plugins folder within the sample project.

  1. ) android : Contains the files needed for the android build.

  2. ) ios : Contains the files needed for the ios build.

  3. ) navergamesdk : contains the cocos2d-x project as well as the files that have to be connected to the respective platforms, such as android and ios.

2. Plugin Installation

  • In order to synchronize the SDK with your company’s Cocos2d-x project, copy the navergamesdk folder within Plugins into the Classes folder within your company’s project.

  • If your company is planning to release on a single platform, either android or ios, from the project, keep only the relevant folder, android or ios, located at the bottom end of the platform and delete the rest.

2-1. NaverGameSDK.h

  • The file contains the written code necessary for the sdk connection.

3. Plugin Application

Include the header file in the location within your company’s project that is trying to use the sdk. (Applied to HelloWorldScene.h for the sample project)

#include "NaverGameSDK.h"
  • If it is unable to find NaverGameSDK.h, the header file has to also be included in the rootProject/CmakeLists.txt as shown in the image below.

Register the header file and the cpp file.
Register the navergamesdk folder.

3-1. NaverGame SDK initialization

During the initializing of Navergame SDK, the options have to be set as shown in the following, and the init() method has to be called.

  • ClientId: The Client Id received after registering the application at developers center upon logging in with a Naver Id.

  • ClientSecret: The client secret received after registering the application at developers center upon logging in with a Naver Id.

  • LoungeId: The Lounge Id received after requesting for an official lounge.

nng::NaverGameSDK::init("UKvNABLDsyEJusJGsXL2", "rK4suc_Qd0", "naver_game_4developer");

3-2. SDK Event Listener Registration

In order to receive the various events sent from the SDK, a listener has to be registered.

//리스너는 NaverGameSDK.h 에 선언되어있습니다.
nng::NaverGameSDK::setSdkListener(this);

3-3. A Look into SDK Support Function

  1. Restoring home banner

    nng::NaverGameSDK::startHomeBanner();
  2. Restoring maintenance banner

    nng::NaverGameSDK::startSorryBanner();
  3. Restoring specific bulletin board

    nng::NaverGameSDK::startBoard(boardId);
  4. Restoring specific post

    A method that immediately runs with the number of the registered post. Under the case of a scheduled notification post that have scheduled through scheduled exposure, the number of the scheduled post must be inputted into FeedId and IsTempFeedId must be inputted as True.

    nng::NaverGameSDK::startFeed(feedId, isTempFeedId);
  5. Terminating sdk

    nng::NaverGameSDK::stopSdk
  6. Restoring country codes

    Obtain the countryCode of the mobile device. It must be called for after the init() method is called in order to obtain the normal value.

    nng::NaverGameSDK::getCountryCode();

    The countryCode is the country code (ISO 3166-1 alpha-2) composed of two alphabets. This enables branch processing by countries within the codes. The notable country codes are as shown in the following. Refer to the link for other country codes.

    Country Code

    Country

    CN

    China

    JP

    Japan

    KR

    Republic of Korea

    TH

    Thailand

    US

    United States of America

Application of the Navergame SDK to the Android Project

The following is the android build environment for the sample project. Please use it as a reference.

  • Cocos2d-x 3.17.2

  • Android Studio 4.2

  • Gradle 4.9 (proj.android/gradle/wrapper/gradle-wrapper.properties)

  • Ndk 16.1.4479499

  • Cmake 3.10.2.4988404 (with Ninja 1.10.2)

1. Add the bridge file (code) that connects Cocos2d-x and Android.

The Plugins folder within the sample project

The android folder content of the Plugins folder

  1. ) com... Near the end of the folder is the NNGSdk.java file that serves as the bridge between android and cocos projects.

  2. ) navergame-sdk-gradle-x.x.x.aar is a Navergame sdk library.

This is the directory structure of the sample project.

1-1. navergame-sdk-gradle-x.x.x.aar

This is the Naver Game SDK library.

  • Paste into the rootProject/proj.android/app/libs folder. If a libs folder is not present, create one.

1-2. NNGSdk.java

The file that has the bridge code that connects Cocos2d-x project and SDK from Android.

  • Paste into the rootProject/proj.android/app/src folder. Paste the entire folder that starts with com..

1-3. NaverGameSDK.cpp

The file that has the bridge code that connects the Android project and Cocos2d-x.

  • Check if the rootProject/Classes/navergamesdk/platform/android/NaverGameSDK.cpp file is present, and if not, find and paste it from the Plugins folder.

  • Depending on the version of cocos2d-x, the JniHelper might be written in a different name, so if the version is different, check.

#include "NaverGameSDK.h"
#include "platform/android/jni/JniHelper.h"

using namespace cocos2d;

namespace nng {
    static bool getStaticMethod(JniMethodInfo &methodinfo, const char *methodName, const char *paramCode) {
        static const char* kCafeSdkClass = "com/navercorp/nng/cocos2dx/sample/NNGSdk";
        return JniHelper::getStaticMethodInfo(methodinfo, kCafeSdkClass, methodName, paramCode);
    }

    static NaverGameSDKListener* sdkListener = nullptr;

    void NaverGameSDK::setSdkListener(NaverGameSDKListener* listener) {
        sdkListener = listener;
    }

    void NaverGameSDK::init(std::string clientId, std::string clientSecret, std::string loungeId) {
        JniMethodInfo t;
        if (getStaticMethod(t, "init","(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V")) {
            jstring _clientId = t.env->NewStringUTF(clientId.c_str());
            jstring _clientSecret = t.env->NewStringUTF(clientSecret.c_str());
            jstring _loungeId = t.env->NewStringUTF(loungeId.c_str());

            t.env->CallStaticVoidMethod(t.classID, t.methodID, _clientId, _clientSecret, _loungeId);

            t.env->DeleteLocalRef(_clientId);
            t.env->DeleteLocalRef(_clientSecret);
            t.env->DeleteLocalRef(_loungeId);
            t.env->DeleteLocalRef(t.classID);
        }
    }

    .
    .
    .

    extern "C" {
        JNIEXPORT void JNICALL
        Java_com_navercorp_nng_cocos2dx_sample_NNGSdk_onSdkStarted(JNIEnv* env, jclass thiz) {
            if (sdkListener == nullptr) return;
            sdkListener->onSdkStarted();
        }

        .
        .
        .
    }
}   /* namespace nng */
  • kCafeSdkClass = "com/navercorp/nng/cocos2dx/sample/NNGSdk";

    • This is the location path of the NNGSdk.java file. If the location path of the NNGSdk.java had been changed, make adjustments according to the relevant location.

  • Java_com_navercorp_nng_cocos2dx_sample_NNGSdk_Funtion네임

    • The is the location path of the NNGSDK.java file. If the location path of the NNGSdk.java had been changed, make adjustments according to the relevant location.

2. Settings Required to Build to Android

1-1. AndroidManifest.xml

  • Add the necessary permissions from the SDK to the rootProject/proj.android/app/AndroidManifest.xml file.

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

1-2. build.gradle

  • Add the SDK and the library needed for the SDK to the rootProject/proj.android/app/build.gradle file.

dependencies {
    implementation project(':libcocos2dx')
    /**
     * Navergame sdk와 필요한 libraries
     */
    implementation files('libs/navergame-sdk-gradle-1.1.0.aar')
    implementation "org.jetbrains.kotlin:kotlin-stdlib:1.3.72"            // Kotlin
    implementation "androidx.viewpager2:viewpager2:1.0.0"
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
    implementation "com.github.bumptech.glide:glide:3.7.0"                // Glide
    implementation "com.squareup.retrofit2:retrofit:2.6.4"                // Retrofit, Gson
    implementation "com.squareup.retrofit2:converter-gson:2.6.4"          // Retrofit, Gson
}

1-3. ndk and cmake installation

  • Instructions for using Android Studio

    • Android Studio -> Preferences -> Search sdk using the search function, and download the ndk and the cmake from the sdk tools tab. (Check Show Package Details.)

1-4. ndk, cmake application

  • Input the ndk and cmake file installation path to the rootProject/proj.android/local.properties file.

3. Building with Android

There are two build methods for Cocos2d-x project with Android.

  • cmake

  • ndk

The exact naming may differ with respect to the version of cocos2d-x, so please check. Using version 3.17.2, it can be checked in the build.gradle file.

3-0. Build Type Application Method

Can be determined from the PROP_BUILD_TYPE property within the rootProject/proj.android/gradle.properties file.

  • If wanting to build with cmake, set PROP_BUILD_TYPE=cmake.

3-1. Building with CMAKE

3-2. Building with NDK

  • Check PROP_BUILD_TYPE=ndk-build within rootProject/proj.android/gradle.properties.

  • Add the files and folder paths necessary for the SDK within rootProject/proj.android/app/jni/Android.mk.

  • Check if the ndk file installation path has been properly inputted into rootProject/proj.andorid/local.properties.

  • Click the build button!

Application of Navergame SDK to iOS Projects

Naver Game iOS SDK supports iOS versions 12.0 and above.

Set the development environment as shown in the following in XCode in order to use NaverGame SDK.

  • Select the app that is going to be run amongst the TARGETS category.

  • Select the Build Setting tab and find Other Linker Flags from the Linking category.

    • If in either Basic or Customized modes, the Other Linker Flag might not appear, and in this case select All mode.

    • It can be easily found by entering Other Linker Flag into the search bar located in the upper right corner.

  • Add the -ObjC option and the -lc++ option to Other Linker Flags.

  • Add the following option to obtain user permission to Info.plist.

    • Privacy - Camera Usage Description

    • Privacy - Photo Library Usage Description

  • Select the app that is going to be run amongst the TARGETS category, and input the Identifier values and URL Schemes values into the URL Types category of the Info tab.

  • The Identifier value can be checked from the General tab of the relevant TARGET.

  • For the URL Schemes value , input the URL Scheme value that was used to register for the application in the developers center after logging in with a Naver Id.

Last updated

Was this helpful?