棱镜SDK简单介绍

若想让游戏上线,渠道接入步骤是不可缺少的,为了避免一对一接入渠道问题,我选择了棱镜SDK,由于棱镜是游戏与渠道SDK的中间层,为CP厂商屏蔽各个渠道SDK之间的差异,整个接入过程,不会改变各个渠道SDK的功能、特性、參数等,对玩家全然透明。

棱镜平台基本工作原理:http://dev.ljsdk.com/ljdocs/lj_principle.html

棱镜技术接入文档(cocos2d-x)::http://dev.ljsdk.com/ljdocs/lj_tech_integration_cpp.html

棱镜SDK下载:http://dev.ljsdk.com/ljdocs/lj_tech_general.html

client接入流程

1.将Demo项目中Classes/GameProxy.h 拷贝到你的C++project中头文件存放的位置,如Cocos2dx项目放入Classes文件夹, 将Classes/gameproxy.cpp 放入源代码文件夹,如Cocos2dx的Classes文件夹:

2.windows平台加入代码例如以下:

HelloWorldScene.h

#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__ #include "cocos2d.h" class HelloWorld : public cocos2d::CCLayer
{
public:
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init(); // there's no 'id' in cpp, so we recommend returning the class instance pointer
static cocos2d::CCScene* scene(); // a selector callback
void menuCloseCallback(CCObject* pSender); void setUserListener(); void loginCallback(CCObject* pSender); void logoutCallback(CCObject* pSender); void chargeCallback(CCObject* pSender); void payCallback(CCObject* pSender); void exitCallback(CCObject* pSender); void showInfo(const char* str); // implement the "static node()" method manually
CREATE_FUNC(HelloWorld); private:
cocos2d::CCLabelTTF* outputLabel;
}; #endif // __HELLOWORLD_SCENE_H__

HelloWorldScene.cpp

#include "HelloWorldScene.h"
#if(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include "GameProxy.h"
#endif USING_NS_CC; CCScene* HelloWorld::scene()
{
// 'scene' is an autorelease object
CCScene *scene = CCScene::create(); // 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::create(); // add layer as a child to scene
scene->addChild(layer); // return the scene
return scene;
} // on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
} CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); CCLabelTTF* pLabel = CCLabelTTF::create("CoCos2d-x SDKTest", "Arial", 30); // position the label on the center of the screen
pLabel->setPosition(ccp(origin.x + visibleSize.width/2,
origin.y + visibleSize.height - pLabel->getContentSize().height));
// add the label as a child to this layer
this->addChild(pLabel, 1); this->outputLabel = CCLabelTTF::create("Output Here", "Arial", 20);
this->outputLabel->setHorizontalAlignment(kCCTextAlignmentLeft);
// position the label on the center of the screen
this->outputLabel->setAnchorPoint(ccp(0, 0));
this->outputLabel->setPosition(ccp(origin.x + visibleSize.width/2, origin.y));
this->addChild(this->outputLabel, 1); // add "HelloWorld" splash screen"
CCSprite* pSprite = CCSprite::create("icon.png"); // position the sprite on the center of the screen
pSprite->setPosition(ccp(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2)); // add the sprite as a child to this layer
this->addChild(pSprite, 0); CCMenuItemFont *loginItem = CCMenuItemFont::create(
"login",
this,
menu_selector(HelloWorld::loginCallback));
CCMenuItemFont *logoutItem = CCMenuItemFont::create(
"logout",
this,
menu_selector(HelloWorld::logoutCallback)); CCMenuItemFont *chargeItem = CCMenuItemFont::create(
"charge",
this,
menu_selector(HelloWorld::chargeCallback)); CCMenuItemFont *payItem = CCMenuItemFont::create(
"pay",
this,
menu_selector(HelloWorld::payCallback)); CCMenuItemFont *exitItem = CCMenuItemFont::create(
"exit",
this,
menu_selector(HelloWorld::exitCallback)); float borderWidth = 0;
float currentYBorder = origin.y + visibleSize.height; float offset = borderWidth + loginItem->getContentSize().height/2; loginItem->setPosition(ccp(origin.x + loginItem->getContentSize().width/2 + borderWidth,
currentYBorder - offset)); currentYBorder -= 2 * offset;
offset = borderWidth + logoutItem->getContentSize().height/2;
logoutItem->setPosition(ccp(origin.x + logoutItem->getContentSize().width/2 + borderWidth ,
currentYBorder - offset)); currentYBorder -= 2 * offset;
offset = borderWidth + chargeItem->getContentSize().height/2;
chargeItem->setPosition(ccp(origin.x + chargeItem->getContentSize().width/2 + borderWidth ,
currentYBorder - offset)); currentYBorder -= 2 * offset;
offset = borderWidth + payItem->getContentSize().height/2;
payItem->setPosition(ccp(origin.x + payItem->getContentSize().width/2 + borderWidth ,
currentYBorder - offset)); currentYBorder -= 2 * offset;
offset = borderWidth + exitItem->getContentSize().height/2;
exitItem->setPosition(ccp(origin.x + exitItem->getContentSize().width/2 + borderWidth ,
currentYBorder - offset)); CCMenu* pMenu = CCMenu::create(loginItem,logoutItem,chargeItem,payItem,exitItem,NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu,1,2); #if(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
this->showInfo(GameProxy::GetAndroidManifestMeta("XMGAME_PRODUCT_CODE"));
#endif return true;
} void HelloWorld::showInfo(const char *info){ this->outputLabel->setString(info);
CCLOG("showinfo %s", info);
} #if(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
class XMUserListenerImpl: public XMUserListener {
private:
HelloWorld * parent;
public:
XMUserListenerImpl(HelloWorld* parent) {
this->parent = parent;
}
virtual void onLoginSuccess(XMUser user, const char *customParams) { // 游戏的登陆逻辑须要写在这里 // 当游戏调用 GameProxy::Login(params) 时,该函数会被调用
// 当中user对象为渠道登陆系统返回的用户相关參数,包括uid token 渠道号等
// 当中params为调用GameProxy::Login( params)时,传入的params
// 确保该函数被调用后,用户能够正确地进入游戏 CCLOG("login success"); stringstream is;
is << "uid : " << user.getUserId() << "\ntoken : " << user.getToken() << "\nchannelId : " << user.getChannelId();
parent->showInfo(is.str().c_str());
GameProxy::SetXMRoleData("1", "hi", "10", "1", "1");
}; virtual void onLoginFailed(const char *reason,
const char *customParams) {
stringstream is;
is << "login failed reason: " << reason << "\ncustomParams: " << customParams;
parent->showInfo(is.str().c_str()); };
virtual void onLogout(const char *customParams) {
// 游戏相关的用户登出注销逻辑须要写在这里 // 当渠道的用户中心界面中点击注销,该函数会被调用
// 当游戏调用 GameProxy::Logout(params) 时,该函数也会被调用
// 当中params为用户调用 GameProxy::Logout(params) 时传入的params
// params能够用来传递一些游戏中的上下文,能够是随意字符串
// 确保游戏中不论什么时候,该函数被调用后,游戏能够正确登出 parent->showInfo("logout");
};
}; class PayCallBackImpl:public PayCallBack{
private:
HelloWorld* parent;
public:
PayCallBackImpl(HelloWorld* parent) {
this->parent = parent;
}
virtual void onPaySuccess(char *successinfo){
stringstream is;
is << "sucess: " <<successinfo;
parent->showInfo(is.str().c_str());
};
virtual void onPayFail(char *failinfo){
stringstream is;
is << "payfailed: " << failinfo;
parent->showInfo(is.str().c_str());
};
}; class ExitCallBackImpl:public ExitCallBack{
public:
virtual void onGameExit(){
CCDirector::sharedDirector()->end();
};
virtual void onNo3rd(){ CCDirector::sharedDirector()->end();
};
}; #endif void HelloWorld::setUserListener(){
#if(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
GameProxy::SetUserListener(new XMUserListenerImpl(this));
#endif
} void HelloWorld::loginCallback(CCObject* pSender)
{
#if(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
this->showInfo("logining");
HelloWorld::setUserListener();
const char *customParams = "login";
GameProxy::Login(customParams);
#endif
} void HelloWorld::logoutCallback(CCObject* pSender){
#if(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
const char *customParams = "logout";
GameProxy::Logout(customParams);
#endif
} void HelloWorld::chargeCallback(CCObject* pSender){
#if(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
const char *itemName = "元宝";
int unitPrice = 10;
int defalutNum = 500;
const char *callBackInfo = "this is callback info...";
const char *callbackUrl = "http://test";
GameProxy::Charge(itemName, unitPrice, defalutNum, callBackInfo, callbackUrl,new PayCallBackImpl(this));
#endif
} void HelloWorld::payCallback(CCObject* pSender){
#if(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
int amount = 10;
const char *unitName = "天币";
int count = 118;
const char *callBackInfo = "this is callback info";
const char *callbackUrl = "http://test"; GameProxy::Pay(amount, unitName, count, callBackInfo, callbackUrl, new PayCallBackImpl(this));
#endif
} void HelloWorld::exitCallback(CCObject* pSender){
#if(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
GameProxy::Exit(new ExitCallBackImpl());
#endif
} void HelloWorld::menuCloseCallback(CCObject* pSender)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
CCMessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert");
#else
CCDirector::sharedDirector()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
#endif
}

3.android平台:

环境搭建:

将Demo项目中libs文件夹下jar包拷贝到游戏项目的libs文件夹下
将Demo项目中assets文件夹下的文件拷贝到游戏项目的assets文件夹下

Android.mk:

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.InsetSDK.org"
android:versionCode="1"
android:versionName="1.0"> <uses-sdk android:minSdkVersion="8"/>
<uses-feature android:glEsVersion="0x00020000" /> <application
android:name="com.xinmei365.game.proxy.XMApplication"
android:label="@string/app_name"
android:icon="@drawable/icon"> <activity android:name=".InsetSDK"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="XMGAME_CHANNEL_CODE" android:value="9f10f46c37214442ba473b5409a05ebf" />
<meta-data android:name="XMGAME_PRODUCT_CODE" android:value="lsjs" /> </application>
<supports-screens android:largeScreens="true"
android:smallScreens="true"
android:anyDensity="true"
android:normalScreens="true"/> <uses-permission android:name="android.permission.INTERNET"/>
</manifest>

Activity的Java代码:

public class InsetSDK extends Cocos2dxActivity{

    protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState); GameProxyNativeStub.init(this, GameProxy.getInstance(), new XMGLThreadRunner() { @Override
public void runOnGLThread(Runnable pRunnable) {
InsetSDK.this.runOnGLThread(pRunnable); }});
GameProxy.getInstance().applicationInit(this);
GameProxy.getInstance().onCreate(this); } public Cocos2dxGLSurfaceView onCreateView() {
Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this);
// InsetSDK should create stencil buffer
glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8); return glSurfaceView;
} static {
System.loadLibrary("cocos2dcpp");
} public void onStop() {
super.onStop();
GameProxy.getInstance().onStop(this);
} public void onDestroy() {
super.onDestroy();
GameProxy.getInstance().onDestroy(this);
} public void onResume() {
super.onResume();
GameProxy.getInstance().onResume(this);
}
public void onPause() {
super.onPause();
GameProxy.getInstance().onPause(this);
}
public void onRestart() {
super.onRestart();
GameProxy.getInstance().onRestart(this);
} protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
GameProxy.getInstance().onActivityResult(this, requestCode, resultCode, data);
}
}

真机执行效果图:

cocos2d-x -- 渠道SDK【棱镜】接入(1)的更多相关文章

  1. 手机游戏渠道SDK接入工具项目分享(一)缘起

    #剧情章节 # 上周刚结束一个外包的项目,开发手机游戏渠道SDK聚合接入工具的,现在有空回顾整理一下这个项目开发过程,因涉嫌商业秘密不会提供项目代码,只谈下开发思路和掉过的坑. 本人多年从事手机互联网 ...

  2. 教你高速高效接入SDK——Unity统一接入渠道SDK(Android篇)

    U8SDK的设计之初,就是为了可以支持各种游戏引擎开发的游戏,而不不过Android的原生平台.眼下一大半的手游,都是採用Unity3D和Cocos2dx开发,那么这里,我们就先来一步步给大家演示,用 ...

  3. U8SDK——游戏接入SDK(只接入抽象框架)

    上一篇文章我们说了整个U8 SDK抽象成的设计,那这篇文章,我们就来验证一下,他是否如我们期待的那样,简单灵活. 正如之前所说,对于每个游戏,只需要接入抽象层,而每个渠道SDK的接入,就是该抽象层的一 ...

  4. cocos2d-x -- 渠道SDK【棱镜】接入(2)

    上一章<cocos2d-x -- 渠道SDK[棱镜]接入(1)>,已经接入好了SDK.如今要准备加入渠道了,以豌豆荚为例. 详细流程: 1.加入渠道:

  5. 手机游戏渠道SDK接入工具项目分享(二)万事开头难

    一般接到任务后程序员们通常都开始着手进行技术调研了,但我这活是项目负责人.还有一大堆事情要先期准备,没人能帮忙. 一.人力配置 考虑的之前已经有一波人搞了大半年,但没有起色,先期也没有太大人力需求,所 ...

  6. 手机游戏渠道SDK接入工具项目分享(三)拨开云雾是个坑

    一直在纠结是先写框架设计还是先写掉过的坑,最后本这娱乐大众的态度先写掉过的坑让大家乐呵下. 项目开发过程中遇问题无数,回顾下8个大坑照成了项目一定程度上延期甚至返工. 项目一开始几个人把现有3家主流的 ...

  7. unity3d如何快速接入渠道SDK之Unity篇

    原文链接: http://bbs.tianya.cn/post-414-53320-1.shtml 首先我们讲一下,为什么要介绍这个插件? 是因为这个插件极大的简化了我对接渠道SDK的工作量,精力和时 ...

  8. Channel SDK (渠道SDK) for Unity

    渠道 英文channel,解释:商品的销售路线,也就是我们开发商(CP)都把游戏开发好了,交付给渠道帮我们运营,帮我们推广,帮我们赚钱. Android和IOS渠道 拿安卓和IOS两大平台来说,它们都 ...

  9. cocos2d 接 android sdk 的一个小坑 关于armbeabi 和 armbeabi-v7a

    cocos2d 接 android sdk 的时候,有些sdk会要求外链到某个工程中,而这个工程的lib文件夹里会包含armbeabi 和 armbeabi-v7a这两个文件夹,如果直接打包会闪退.只 ...

随机推荐

  1. 使用yiic安装开发web应用和解决yiic不是内部命令

    使用yii创建应用程序,推荐博客:http://www.cnblogs.com/waitingbar/archive/2013/02/28/2937308.html 把php.exe加入为系统环境变量 ...

  2. 百度map android sdk3.5实现定位 并跳转的指定坐标,加入标记

    前几天又下载了新的百度地图sdk,3.5版本号.发现百度地图api有了较大变化 定位和3.0版本号差点儿相同 可是设置地图中心和加入maker标记有较大变化 设置地图中心点 // 定义地图状态zoom ...

  3. 【DRP】删除递归树的操作

    正如图呈现的树结构.本文从任意节点删除树形结构.提供解决方案 图中,不包括其他结点的是叶子结点.包括其他结点的是父结点,即不是叶子结点. 一 本文的知识点: (1)递归调用: 由于待删除的结点的层次是 ...

  4. 以todomvc为例分析knockout、backbone和angularjs

    一.整体结构 项目github地址https://github.com/tastejs/todomvc/ 排除通用的css样式文件和引用的js库文件,仅看html和js 1.1 knockoutjs版 ...

  5. OCP-1Z0-051-题目解析-第30题

    30. Evaluate the following CREATE TABLE commands: CREATE TABLE orders (ord_no NUMBER(2) CONSTRAINT o ...

  6. poj1236 有向图加边变成强连通图

    给我们一个有向图,有两个问题 1.最少要给多少个点发消息,才能使得所有的点都收到消息(消息可以随边传递) 2.最少需要多少条边才能使得图变成强连通图 对于一个强连通分量,可以当做一个点来考虑,所以我们 ...

  7. Xamarin For Visual Studio 3.7.165 完整离线破解版

    原文 Xamarin For Visual Studio 3.7.165 完整离线破解版 Xamarin For Visual Studio就是原本的Xamarin For Android 以及 Xa ...

  8. Quasi-Newton Method--LBFGS

    Quasi-Newton Method Quasi-Newton Method每一步计算过程中仅涉及到函数值和函数梯度值计算,这样有效避免了Newton Method中涉及到的Hessian矩阵计算问 ...

  9. cocos2d-x: 33种切换场景

    [1]:CCTransitionCrossFade::create(时间,目标场景); //慢慢淡化到还有一场景 [2]:CCTransitionFade::create(时间,目标场景); //本场 ...

  10. 哈希表之bkdrhash算法解析及扩展

    BKDRHASH是一种字符哈希算法,像BKDRHash,APHash.DJBHash,JSHash,RSHash.SDBMHash.PJWHash.ELFHash等等,这些都是比較经典的,通过http ...