http://cn.matchvs.com/portal/index.jsp
matchvs官网
下面讲解如何进行mac上 安卓ios双客户端配置
1、新建cocos2dx项目 我的版本为3.10
用xcode打开
2、将depences复制到项目目录
并把依赖文件拖入 buildprase
配置library search path
$(SRCROOT)/../dependencies/libs_ios
$(SRCROOT)/../dependencies/libs_mac
注意iOS mac分开设置
3、添加头文件到classes 直接拖过去
4、mac上的就可以运行了
iOS真机测试:
遇到的问题和解决都在上面了
路径那里设置一下递归查找
签名问题一般点一下就行 不行自己百度 改改前缀什么的
5、配置安卓开发
粘
贴官方文档:成为开发者 成为MatchVS开发者,获取MatchVS开发者的唯一ID
(developerID),在成为开发者后,可以向MatchVS提交游戏应用,MatchVS会为每一款游戏生成一个唯一的游戏ID
(GameID),到此,开发者可以开始为对战做准备了!为游戏获取MatchVS_APP_KEY开发者需要进入cn.matchvs.com,注册成
为MatchVS会员,并提交游戏信息,即可获取与游戏绑定的MatchVS_APP_KEY,需提交的游戏信息包括: 游戏名称,提交后不可修
改 应用包名,如com.matchvs.game,提交后不可修改 合作方式,对战或联运,提交后不可修改对战游戏,还需要设置对战结果配
置及对战排行数据配置,详情见后文。在提交上述内容后,会给合作商的游戏分配唯一的MatchVS_APP_KEY,此MatchVS_APP_KEY用
于识别唯一的MatchVS游戏。 注意:合作商在拥有多款不同的游戏时,需要为每一款游戏申请MatchVS_APP_KEY。对战前的准备
第一步,将libKOFrameWorkCocos2dx.so及libGameHelper.so考入cocos项目中的proj.android的jni\prebuilt中
项目配置
合作商根据需要将库文件拷贝如应用中的libs目录下,之后需要将申请到的MatchVS_APP_KEY增加到应用项目的AndroidManifest.xml中,并且申请网络访问权限,具体如下:
<uses-permission android:name="android.permission.INTERNET"/>
<application>
<meta-data android:value="[MatchVS_APP_KEY内容]" android:name="MatchVS_APP_KEY"></meta-data>
</application>
其中,meta-data中的android:value中填写游戏的MatchVS_APP_KEY
必要的权限
<!-- 网络权限组 -->
<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" />
<!-- 读写SD卡权限组 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- 读取IMEI的权限 -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
库引用
第一步,将libKOFrameWorkCocos2dx.so及libGameHelper.so考入cocos项目中的proj.android的jni\prebuilt中
第二步,修改Android.mk,在文件开始位置加入以下内容:
#添加cocos引擎代码目录
#cocos引擎的版本此处为:cocos2d-x-3.8(请选择开发机器对应版本)
COCO2D_PATH := $(COCOS_FRAMEWORK)/cocos2d-x-3.8
#------------------prebuild libKOFrameWork.so ----------------
include $(CLEAR_VARS)
LOCAL_MODULE := KOFrameRuntime
LOCAL_SRC_FILES := prebuilt/$(TARGET_ARCH_ABI)/libKOFrameWorkCocos2dx.so
Include $(PREBUILT_SHARED_LIBRARY)
#-------------------------------------------------------------
#------------------prebuild libGameHelper.so -----------------
include $(CLEAR_VARS)
LOCAL_MODULE := KOGameHelperRun
LOCAL_SRC_FILES := prebuilt/$(TARGET_ARCH_ABI)/libGameHelper.so
Include $(PREBUILT_SHARED_LIBRARY)
#-------------------------------------------------------------
#------------------ libraries --------------------------------
LOCAL_SHARED_LIBRARIES := KOFrameRuntime
LOCAL_SHARED_LIBRARIES += KOGameHelperRun
#-------------------------------------------------------------
第三步,将jar文件拷入jars(Cocos-Studio)或libs(Eclipse)目录
第四步,将include下的头文件考入cocos项目的Classes中
初始化
MatchVS SDK for cocos2d-x版本初始分为Java和C++两个步骤,开发者在执行完下列步骤后即可使用MatchVS的功能接口。
JNI代理服务
初始化JNI代理服务,仅需要在应用启动时调用如下方法(Application.onCreate 或 Activity.onCreate均可):
import com.matchvs.sdk.engine.api.MatchVSService;
public class AppActivity extends Cocos2dxActivity{
@Override
Protected void onCreate(BundlesavedInstanceState){
MatchVSService.InitService(
getApplicationContext(),/* 推荐使用ApplicationContext */
102000,/* 游戏ID */
1,/* 游戏版本 */
1/* 开发者ID */
);
super.onCreate(savedInstanceState);
}
}
// 注:游戏版本一般为1,如果开发者需要区别不同版本的对战可以申请增加
初始化服务模块
在C++使用MatchVS用户、用户及对战接口时,需要先初始化服务模块,注册事件回调。初始化方法在应用声明周期中仅需调用一次,开发者可以在游戏初始化时进行。
CMatchVSUser::getInstance()->initWithCallback(new UserCallback);
CMatchVSPay::getInstance()->initWithCallback(new PayCallback);
CMatchVSLobby::getInstance()->initWithCallback(newLobbyCallback);
Class UserCallback:public CMatchVSUserCallback{
// 开发者实现回调接口
}
Class PayCallback:public CMatchVSPayCallback{
// 开发者实现回调接口
}
Class LobbyCallback:public CMatchVSLobbyCallback{
// 开发者实现回调接口
}
xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.cocos2dx.buildtest" android:versionCode="1" android:versionName="1.0" android:installLocation="auto"> <uses-sdk android:minSdkVersion="9"/> <uses-feature android:glEsVersion="0x00020000" /> <application android:label="@string/app_name" android:icon="@drawable/icon"> <!-- Tell Cocos2dxActivity the name of our .so --> <meta-data android:name="android.app.lib_name" android:value="cocos2dcpp" /> <meta-data android:value="[hpbfHtWaqVtfhhyFN6wOPTPnRNJbFsxo" android:name="MatchVS_APP_KEY"/> <activity android:name="org.cocos2dx.cpp.AppActivity" android:label="@string/app_name" android:screenOrientation="landscape" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:configChanges="orientation|keyboardHidden|screenSize"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <supports-screens android:anyDensity="true" android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true"/> <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" /> <!-- 读写SD卡权限组 --> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <!-- 读取IMEI的权限 --> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> </manifest>
#!/usr/bin/python # build_native.py # Build native codes # # Please use cocos console instead import sys import os, os.path import shutil from optparse import OptionParser def build(build_mode): current_dir = os.path.dirname(os.path.realpath(__file__)) cocos_root = os.path.join(current_dir, "../cocos2d") app_android_root = os.path.join(current_dir, "../") if build_mode is None: build_mode = 'debug' elif build_mode != 'release': build_mode = 'debug' command = 'cocos compile -p android -s %s -m %s' % (app_android_root, build_mode) if os.system(command) != 0: raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!") def getFileNames(path): fileList = [] files = os.listdir(path) for f in files: if(os.path.isfile(path + '/' + f)): if(f[0] == '.' or f.find(".cpp")==-1): continue fileList.append(f) return fileList def inAndroidmkClass(): current_dir = os.path.dirname(os.path.realpath(__file__)) print current_dir[:current_dir.rfind("/")] anfile_dir = os.path.join(current_dir, "jni/Android.mk") print "anfile_dir:"+anfile_dir class_dir =os.path.join(current_dir[:current_dir.rfind("/")],"Classes") print "class_dir:"+class_dir f=open(anfile_dir); txt=f.read(); f.close(); pos=txt.find("LOCAL_MODULE_FILENAME"); pos1=txt[pos:].find("\n") pre=txt[0:pos+pos1+2]; pos2=txt.find("LOCAL_C_INCLUDES"); last=txt[pos2:]; intxt="LOCAL_SRC_FILES := hellocpp/main.cpp \\\n"; files= getFileNames(class_dir); for f in files: intxt+=" ../../Classes/"+f+" \\\n"; intxt+="\n"; f=open(anfile_dir,"w"); f.write(pre+intxt+last); f.close(); print "write to android.mk completed" # print pre+intxt+last; # -------------- main -------------- if __name__ == '__main__': inAndroidmkClass(); parser = OptionParser() parser.add_option("-n", "--ndk", dest="ndk_build_param", help='it is not used', action="append") parser.add_option("-p", "--platform", dest="android_platform", help='it is not used') parser.add_option("-b", "--build", dest="build_mode", help='the build mode for java project,debug[default] or release.Get more information,please refer to http://developer.android.com/tools/building/building-cmdline.html') (opts, args) = parser.parse_args() print "Please use cocos console instead.\n" build(opts.build_mode)
mk
LOCAL_PATH := $(call my-dir) #添加cocos引擎代码目录 COCO2D_PATH := /Applications/Cocos/Cocos2d-x #导入NDK_MODULE_PATH $(call import-add-path,$(COCO2D_PATH)/cocos2d-x-3.10) $(call import-add-path,$(COCO2D_PATH)/cocos2d-x-3.10/cocos) $(call import-add-path,$(COCO2D_PATH)/cocos2d-x-3.10/external) #------------------prebuild libKOFrameWork.so ---------------- include $(CLEAR_VARS) LOCAL_MODULE := KOFrameRuntime LOCAL_SRC_FILES := prebuilt/$(TARGET_ARCH_ABI)/libKOFrameWorkCocos2dx.so include $(PREBUILT_SHARED_LIBRARY) #------------------------------------------------------------- #------------------prebuild libGameHelper.so ----------------- include $(CLEAR_VARS) LOCAL_MODULE := KOGameHelperRun LOCAL_SRC_FILES := prebuilt/$(TARGET_ARCH_ABI)/libGameHelper.so include $(PREBUILT_SHARED_LIBRARY) #------------------------------------------------------------- include $(CLEAR_VARS) LOCAL_MODULE := cocos2dcpp_shared LOCAL_MODULE_FILENAME := libcocos2dcpp LOCAL_SRC_FILES := hellocpp/main.cpp \ ../../Classes/AppDelegate.cpp \ ../../Classes/CardSprite.cpp \ ../../Classes/GameBoard.cpp \ ../../Classes/GameLayer.cpp \ ../../Classes/GameScene.cpp \ ../../Classes/HelloWorldScene.cpp \ ../../Classes/LoadingScene.cpp \ ../../Classes/MainMenu.cpp \ ../../Classes/MatchScene.cpp \ ../../Classes/MatchVSDemoCommon.cpp \ ../../Classes/MatchVSDemoLobbyPayHandler.cpp \ ../../Classes/MatchVSDemoUserBattleHandler.cpp \ ../../Classes/PlayerData.cpp \ ../../Classes/SmallBoard.cpp \ ../../Classes/SmartRes.cpp \ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../Classes/MatchVS_include LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../Classes/json LOCAL_CFLAGS += -DCOCOS2D_DEBUG=1 # _COCOS_HEADER_ANDROID_BEGIN # _COCOS_HEADER_ANDROID_END LOCAL_STATIC_LIBRARIES := cocos2dx_static LOCAL_SHARED_LIBRARIES := KOFrameRuntime LOCAL_SHARED_LIBRARIES += KOGameHelperRun # _COCOS_LIB_ANDROID_BEGIN # _COCOS_LIB_ANDROID_END include $(BUILD_SHARED_LIBRARY) $(call import-module,./prebuilt-mk) # _COCOS_LIB_IMPORT_ANDROID_BEGIN # _COCOS_LIB_IMPORT_ANDROID_END
/**************************************************************************** Copyright (c) 2008-2010 Ricardo Quesada Copyright (c) 2010-2012 cocos2d-x.org Copyright (c) 2011 Zynga Inc. Copyright (c) 2013-2014 Chukong Technologies Inc. http://www.cocos2d-x.org Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ package org.cocos2dx.cpp; import org.cocos2dx.lib.Cocos2dxActivity; import com.matchvs.sdk.engine.api.MatchVSService; import android.os.Bundle; public class AppActivity extends Cocos2dxActivity { static{ System.loadLibrary("GameHelper"); System.loadLibrary("KOFrameWorkCocos2dx"); } @Override protected void onCreate(Bundle savedInstanceState) { MatchVSService.InitService( getApplicationContext(), 102000, /* 游戏ID */ 1, /* 游戏版本 */ 1 /* 开发者ID */ ); super.onCreate(savedInstanceState); } }