-
Notifications
You must be signed in to change notification settings - Fork 1
Getting Started
This is our simple 1, 2, 3. Read on for a detailed description of how to integrate cocos2dx-store with your project.
Make sure you've cloned or downloaded the Cocos2d-x framework, also make sure you're working with version 2.x. Once you've downloaded and extracted the framework, clone cocos2dx-store into the extensions directory of the framework.
$ cd $COCOS2DX_DIR
$ git clone --recursive [email protected]:soomla/cocos2dx-store.git extensions/cocos2dx-store
cocos2dx-store depends on our fork of the jasson library. Make sure you clone that into the external directory.
$ cd $COCOS2DX_DIR
$ git clone [email protected]:vedi/jansson.git
Now that you've downloaded everything, it's time to begin integrating cocos2dx-store into your project. Different things need to be done depending on the target platform, currently the only supported targets are Android and iOS.
cocos2dx-store is a Cocos2d-x C++ library that communicates with with our Android library (android-store) through JNI calls. Thus, your project needs to be set up to use android-store.
Add the following to your classpath:
$COCOS2DX_DIR/extensions/cocos2dx-store/android/src
$COCOS2DX_DIR/extensions/cocos2dx-store/submodules/android-store/SoomlaAndroidStore/src
$COCOS2DX_DIR/extensions/cocos2dx-store/submodules/android-store/SoomlaAndroidStore/libs/square-otto-1.3.2.jar
In your Android.mk
file, make sure to declare you are using cocos2dx-store as a static library, and import it:
LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_store_static
$(call import-module, extensions/cocos2dx-store/android/jni)
Your AndroidManifest.xml
also needs to be updated. In-app billing requires you to add the following permissions to your application:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.android.vending.BILLING" />
Android In-App Billing version 3 requires you to conduct all of your purchases in a single Activity. We didn't like this idea so, as a workaround, we open a blank, translucent activity to conduct each purchase. Add this activity to your manifest:
<activity android:name="com.soomla.store.StoreController$IabActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"/>
Note: Leave the management of this activity to cocos2dx-store, do not in any way attempt to open it on your own.
Finally, in your main Cocos2dxActivity
(The one your Cocos2d-x application runs in), call the following in the onCreateView
method:
Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this);
StoreControllerBridge.setGLView(glSurfaceView);
SoomlaApp.setExternalContext(getApplicationContext());
As with Android, cocos2dx-store is a Cocos2d-x C++ library that communicates with with our iOS library (ios-store). Thus, your project needs to be set up to use ios-store.
Add the following directories to your XCode project:
$COCOS2DX_DIR/extensions/cocos2dx-store/ios
$COCOS2DX_DIR/extensions/cocos2dx-store/Soomla
$COCOS2DX_DIR/extensions/cocos2dx-store/submodules/ios-store/SoomlaiOSStore
Also make sure you have these 3 Frameworks linked to your XCode project:
- Security
- StoreKit
- libsqlite3.0.dylib
Now that you've set up the native frameworks, it's time to begin working with cocos2dx-store. When using any of the cocos2dx-store functions, make sure to include the Soomla.h
header:
cpp #include "Soomla.h"
You can also include individual classes if you like, but this is not recommended. cocos2dx-store keeps all of its classes in its own namespace,
soomla
, so don't worry about namespace pollution.
-
To start things off, create your own implementation of
CCIStoreAssets
. This is the class that defines your store's assets. More information on implementingCCIStoreAssets
can be found here. -
Now, initialize
CCStoreController
when your application starts up. This is done by passing over an instance of your assets class toCCStoreController
, and aCCDictionary
containing various parameters:CCDictionary *storeParams = CCDictionary::create(); storeParams-> setObject(CCString::create("<SOOMLA Secret>"), "soomSec"); storeParams-> setObject(CCString::create("<Custom Secret>"), "customSecret"); #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) storeParams-> setObject(CCString::create("<Android Public Key>"), "androidPublicKey"); #endif soomla::CCStoreController::createShared(<YourAssetsClass>::create(), storeParams);
-
Soomla Secret
: a primary encryption key for your application's store data. Choose it wisely, once set, it cannot be changed. -
Custom Secret
: a secondary encryption key, this also can't be changed. -
Android Public Key
: the public key you received from the Google Play Developer Console.
-
-
Whenever you open or close the store scene, you need to notify
CCStoreController
that the store is opening or closing. This is done by using thestoreOpening()
andstoreClosing()
methods:
/* Before showing the store scene */
soomla::CCStoreController::sharedStoreController()->storeOpening();
CCDirector::sharedDirector()->replaceScene(storeScene);
/* Before hiding the store scene */
soomla::CCStoreController::sharedStoreController()->storeClosing();
CCDirector::sharedDirector()->replaceScene(gameScene);
**You are now ready to use *cocos2dx-store* in your project. Enjoy!**