标签:
管理提醒: 本帖被 fm2010 设置为精华(2014-11-12)
|
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \ $(LOCAL_PATH)/../protocols/android \ $(LOCAL_PATH)/../protocols/include |
LOCAL_WHOLE_STATIC_LIBRARIES += PluginProtocolStatic |
|
$(call import-module,protocols/android) |
|
if platform = = ‘win32‘ : ndk_module_path = ‘NDK_MODULE_PATH=%s;%s;%s/external;%s/cocos‘ % ( "./" ,cocos_root, cocos_root, cocos_root) else : ndk_module_path = ‘NDK_MODULE_PATH=%s:%s:%s/external:%s/cocos‘ % ( "./" ,cocos_root, cocos_root, cocos_root) |
|
"ndk_module_path" :[ "../cocos2d" , "../cocos2d/cocos" , "../cocos2d/external" , "" ], |
|
< uses-permission android:name = "android.permission.INTERNET" /> < uses-permission android:name = "android.permission.ACCESS_NETWORK_STATE" /> < uses-permission android:name = "android.permission.ACCESS_WIFI_STATE" /> < uses-permission android:name = "android.permission.RESTART_PACKAGES" /> < uses-permission android:name = "android.permission.KILL_BACKGROUND_PROCESSES" /> |
|
#include "PluginJniHelper.h" using namespace anysdk::framework ; |
|
PluginJniHelper::setJavaVM(vm); |
|
import com.anysdk.framework.PluginWrapper; protected void onCreate(Bundle savedState) { super .onCreate(savedState); PluginWrapper.init( this ); } |
|
import android.content.Intent; @Override protected void onResume() { PluginWrapper.onResume(); super .onResume(); } @Override public void onPause(){ PluginWrapper.onPause(); super .onPause(); } @Override protected void onActivityResult( int requestCode, int resultCode, Intent data){ PluginWrapper.onActivityResult(requestCode, resultCode, data); super .onActivityResult(requestCode, resultCode, data); } @Override protected void onNewIntent(Intent intent) { PluginWrapper.onNewIntent(intent); super .onNewIntent(intent); } |
|
public class wrapper { public static native void nativeInitPlugins(); } |
|
extern "C" { JNIEXPORT void JNICALL Java_org_cocos2dx_cpp_wrapper_nativeInitPlugins(JNIEnv* env, jobject thiz) { PluginChannel::getInstance()->loadPlugins(); } } |
|
wrapper.nativeInitPlugins(); |
|
std::string oauthLoginServer = "http://oauth.anysdk.com/api/OauthLoginDemo/Login.php" ; std::string appKey = "BC26F841-DAC5-9244-D025-759F49997A28" ; std::string appSecret = "1dff378a8f254ec8ad4b492cae72381b" ; std::string privateKey = "696064B29E9A0B7DDBD6FCB88F34A555" ; _agent = AgentManager::getInstance(); _agent->init(appKey,appSecret,privateKey,oauthLoginServer); |
|
_agent->loadALLPlugin(); |
|
_pluginUser = _agent->getUserPlugin(); if (_pluginUser) { _pluginUser->setDebugMode( true ); _pluginUser->setActionListener( this ); } _pluginsIAPMap = _agent->getIAPPlugin(); std::map<std::string , ProtocolIAP*>::iterator iter; for (iter = _pluginsIAPMap->begin(); iter != _pluginsIAPMap->end(); iter++) { (iter->second)->setDebugMode( true ); (iter->second)->setResultListener( this ); } |
|
void PluginChannel::login() { if (_pluginUser) { _pluginUser->login(); } } |
|
void PluginChannel::payment() { if (_pluginsIAPMap) { std::map<std::string, std::string> productInfo; productInfo[ "Product_Price" ] = "1" ; productInfo[ "Product_Id" ] = "1" ; productInfo[ "Product_Name" ] = "豌豆荚测试a1" ; productInfo[ "Server_Id" ] = "13" ; productInfo[ "Product_Count" ] = "1" ; productInfo[ "Role_Id" ] = "1" ; productInfo[ "Role_Name" ] = "1" ; productInfo[ "Role_Grade" ] = "1" ; productInfo[ "Role_Balance" ] = "1" ; std::map<std::string , ProtocolIAP*>::iterator it = _pluginsIAPMap->begin(); if (_pluginsIAPMap->size() == 1) { (it->second)->setDebugMode( true ); (it->second)->payForProduct(productInfo); } else if (_pluginsIAPMap->size() > 1) { //多支付,游戏开发商自己处理相关UI及界面 } } } |
|
void PluginChannel:: exit () { if (_pluginUser && _pluginUser->isFunctionSupported( "exit" )) { _pluginUser->callFuncWithParam( "exit" ,NULL); } } |
|
void PluginChannel::onActionResult(ProtocolUser* pPlugin, UserActionResultCode code, const char * msg) { switch (code) { case kExitPage: //退出游戏回调 purge(); Director::getInstance()->end(); break ; } } |
|
PluginChannel::~PluginChannel() { destroy(); unloadPlugins(); } void PluginChannel::destroy() { if (_pluginUser && _pluginUser->isFunctionSupported( "destroy" )) { _pluginUser->callFuncWithParam( "destroy" ,NULL); } } void PluginChannel::unloadPlugins() { _agent->unloadALLPlugin(); } |
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #include "PluginChannel.h" #endif |
|
void MainMenuScene::startgame_callback() { CCLOG( "login" ); #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) CCLOG( "PluginChannel" ); bReady = true ; PluginChannel::getInstance()->login(); //调用渠道登陆 #else CCLOG( "startgame_callback" ); CocosDenshion::SimpleAudioEngine::getInstance()->stopBackgroundMusic(); GameLayer::isDie= false ; auto scene = (LoadingScene::audioloaded) ? HelloWorld::createScene() :LoadingScene::createScene(); Director::getInstance()->replaceScene(scene); CCLOG( "startgame_callback" ); #endif } |
|
void MainMenuScene::update( float dt){ pRate+=0.01; plane->setPosition3D(Vec3(visible_size_macro.width/2+50,480-20* sin (1.05*pRate),0)); #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) if (PluginChannel::getInstance()->isLogined()&&bReady) //判断登陆状态 { CocosDenshion::SimpleAudioEngine::getInstance()->stopBackgroundMusic(); GameLayer::isDie= false ; auto scene = (LoadingScene::audioloaded) ? HelloWorld::createScene() :LoadingScene::createScene(); Director::getInstance()->replaceScene(scene); } #endif } |
|
void MainMenuScene::recharge_callback() { CCLOG( "recharge" ); #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) CCLOG( "PluginChannel" ); PluginChannel::getInstance()->payment(); //调用渠道支付 #else #endif } |
|
setKeyboardEnabled( true ); |
|
void MainMenuScene::onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event) { #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) switch (keyCode) { case EventKeyboard::KeyCode::KEY_BACK: PluginChannel::getInstance()-> exit (); break ; } #endif } |
标签:
原文地址:http://www.cnblogs.com/wdd-123/p/4704066.html