kbengine_js_plugins

改动(2017/7/6)

由于Cocos Creator使用严格模式的js,而原本的kbengine_js_plugins是非严格模式的,因此为了兼容和方
便Cocos Creator开发的同学,本人对此脚本做了相应的修改,并共享出来。
1:修改了继承的实现方式(旧版本使用callee,严格模式下不能用callee)
2:变量名的定义(严格模式下,全局变量需要显式声明,并且为了防止全局命名污染,因此在变量名前加入了var声明为局部变量)
3:导出KBEngine对象
4:集成GameObject在该插件中

在Cocos Creator使用此脚本的步骤(2017/7/6)

1:复制此脚本到Creator新建的工程的脚本目录下(不要使用插件模式),请参考cocos官方文档:
http://www.cocos.com/docs/creator/scripting/plugin-scripts.html
http://www.cocos.com/docs/creator/scripting/third-party-module.html 2:然后可以定义自己的实体类文件例如,Account.js
var KBEngine = require("kbengine");//使用require引入KBEngine
/*-----------------------------------------------------------------------------------------
entity
-----------------------------------------------------------------------------------------*/
KBEngine.Account = KBEngine.GameObject.extend(
{
__init__ : function()
{
this._super();
KBEngine.Event.fire("onLoginSuccessfully", KBEngine.app.entity_uuid, this.id, this);
},
}
3:或者在cocos creator的组件类里面使用,例如:ClientApp.js
var KBEngine = require("kbengine");//使用require引入KBEngine
cc.Class({
extends: cc.Component, properties: {
ip : "127.0.0.1",
port:"20013",
}, // use this for initialization
onLoad: function () {
var args = new KBEngine.KBEngineArgs();
args.ip = this.ip;
args.port = this.port;
KBEngine.create(args);
},
});

Usage

1: Create KBEngine
// Initialization
var args = new KBEngine.KBEngineArgs(); args.ip = "127.0.0.1";
args.port = 20013;
KBEngine.create(args); 2: Implment the KBE defined entity (including the client part)
See: kbengine\kbengine_demos_assets\scripts\entities.xml,hasClient="true" need to implment
<Account hasClient="true"></Account>
<Monster hasClient="true"></Monster>
<Gate hasClient="true"></Gate>
<Space/> KBEngine.Account = KBEngine.Entity.extend(
{
// entity initialization
__init__ : function()
{
this._super();
}
} Call entity server method
entity.baseCall("base_func", 1, "arg2", "argN")
entity.cellCall("cell_func", 1, "arg2", "argN") 3: Monitor KBE-plugins event
For example:
var StartSceneLayer = Class.extend({
{
installEvents : function()
{
KBEngine.Event.register("onConnectionState", this, "onConnectionState");
} onConnectionState : function(success)
{
// KBE-plugins event fired
}
} 4: Fire events to the KBE-plugins
For example:
KBEngine.Event.fire("login", this.usernamebox.getString(), this.passwordbox.getString(), "kbengine_cocos2d_js_demo");

KBE-Plugin fire-out events(KBE => Unity):

Entity events:
onEnterWorld
Description:
Entity enter the client-world. Event-datas:
Enity onLeaveWorld
Description:
Entity leave the client-world. Event-datas:
Enity onEnterSpace
Description:
Player enter the new space. Event-datas:
Enity onLeaveSpace
Description:
Player enter the space. Event-datas:
Enity onCreateAccountResult
Description:
Create account feedback results. Event-datas:
uint16: retcode
http://kbengine.org/docs/configuration/server_errors.html bytes: datas
If you use third-party account system, the system may fill some of the third-party additional datas. onControlled
Description:
Triggered when the entity is controlled or out of control. Event-datas:
Enity
bool: isControlled onLoseControlledEntity
Description:
Lose controlled entity. Event-datas:
Enity set_position
Description:
Sets the current position of the entity. Event-datas:
Enity set_direction
Description:
Sets the current direction of the entity. Event-datas:
Enity updatePosition
Description:
The entity position is updated, you can smooth the moving entity to new location. Event-datas:
Enity Protocol events:
onVersionNotMatch
Description:
Engine version mismatch. Event-datas:
string: clientVersion
string: serverVersion onScriptVersionNotMatch
Description:
script version mismatch. Event-datas:
string: clientScriptVersion
string: serverScriptVersion Loginapp_importClientMessages
Description:
Importing the message protocol for loginapp and client. Event-datas:
No datas. Baseapp_importClientMessages
Description:
Importing the message protocol for baseapp and client. Event-datas:
No datas. Baseapp_importClientEntityDef
Description:
Protocol description for importing entities. Event-datas:
No datas. Login and Logout status:
onLoginBaseapp
Description:
Login to baseapp. Event-datas:
No datas. onReloginBaseapp
Description:
Relogin to baseapp. Event-datas:
No datas. onKicked
Description:
Kicked of the current server. Event-datas:
uint16: retcode
http://kbengine.org/docs/configuration/server_errors.html onLoginFailed
Description:
Login failed. Event-datas:
uint16: retcode
http://kbengine.org/docs/configuration/server_errors.html onLoginBaseappFailed
Description:
Login baseapp failed. Event-datas:
uint16: retcode
http://kbengine.org/docs/configuration/server_errors.html onReloginBaseappFailed
Description:
Relogin baseapp failed. Event-datas:
uint16: retcode
http://kbengine.org/docs/configuration/server_errors.html onReloginBaseappSuccessfully
Description:
Relogin baseapp success. Event-datas:
No datas. Space events:
addSpaceGeometryMapping
Description:
The current space is specified by the geometry mapping.
Popular said is to load the specified Map Resources. Event-datas:
string: resPath onSetSpaceData
Description:
Server spaceData set data. Event-datas:
int32: spaceID
string: key
string value onDelSpaceData
Description:
Server spaceData delete data. Event-datas:
int32: spaceID
string: key Network events:
onConnectionState
Description:
Status of connection server. Event-datas:
bool: success or fail onDisconnected
Description:
Status of connection server. Event-datas:
No datas.

KBE-Plugin fire-in events(Unity => KBE):

createAccount
Description:
Create new account. Event-datas:
string: accountName
string: password
bytes: datas
Datas by user defined.
Data will be recorded into the KBE account database, you can access the datas through the script layer.
If you use third-party account system, datas will be submitted to the third-party system. login
Description:
Login to server. Event-datas:
string: accountName
string: password
bytes: datas
Datas by user defined.
Data will be recorded into the KBE account database, you can access the datas through the script layer.
If you use third-party account system, datas will be submitted to the third-party system. reloginBaseapp
Description:
Relogin to baseapp. Event-datas:
No datas. resetPassword
Description:
Reset password. Event-datas:
string: accountName newPassword
Description:
Request to set up a new password for the account.
Note: account must be online Event-datas:
string: old_password
string: new_password bindAccountEmail
Description:
Request server binding account Email.
Note: account must be online Event-datas:
string: emailAddress
开源地址:
https://github.com/scanor/kbengine_js_plugins

kbengine_js_plugins 在Cocos Creator中适配的更多相关文章

  1. Cocos Creator 中 _worldMatrix 到底是什么(上)

    Cocos Creator 中 _worldMatrix 到底是什么(上) 1. (矩阵)Matrix是什么,有什么用 (矩阵)Matrix一个神奇的存在?在开发过程中对里边各项值的含义是不是抓耳挠腮 ...

  2. 在 Cocos Creator 中使用 Protobufjs(一)

    一. 环境准备 我一直在探索Cocos H5正确的开发姿势,目前做javascript项目已经离不开 nodejs.npm或grunt等脚手架工具了. 1.初始化package.json文件 npm ...

  3. Cocos Creator 中 _worldMatrix 到底是什么(中)

    Cocos Creator 中 _worldMatrix 到底是什么(中) 1. 中篇摘要 在上篇中主要做了三件事 简单表述了矩阵的基本知识,以及需要涉及到的三角函数知识 推导了图形变换中 位移 .旋 ...

  4. Cocos Creator中按钮组件数组的使用

    Cocos Creator游戏开发中经常使用到按钮,特别是大量按钮的情况,此时使用数组来管理这些按钮就显得更具通用性.我大致走了一下官方的示例,好像没有发现有这个小内容(或者有,但我却是没有找到),于 ...

  5. cocos creator屏幕适配的一些知识点

    一. cocos creator 提供的几种适配策略 EXACT_FIT: 整个应用程序在指定区域可见,无需尝试保留原始纵横比.可能会出现失真,应用程序会被拉伸或压缩.也就是说设计分辨率的长和宽不会等 ...

  6. Cocos Creator 中的动作系统那些事儿

    动作系统就是可以在一定的时间内实现位移.旋转.缩放.跳动等各种动作. 需要注意的是,动作系统跟 Cocos Creator 编译器的动画系统不同,动作系统是面向程序员的API接口,而动画系统是通过编译 ...

  7. Cocos Creator iPhoneX适配的解决办法

    研究了5个小时的iPhoneX适配. 从catalog,storyboard,safearea等一系列文章中发现.如果我们想完全撑满全屏.那直接建一个storyboard就好了.但撑满全屏后,流海就是 ...

  8. cocos creator游戏适配这事

    在想cocos适配之前,我们想想网页是怎么适配的.浏览器有各种规格,网页的一般做法是:背景图片铺满,网页内容保持在背景图片上居中,就实现了适应或者适配.css一般这样: .bg{ height:582 ...

  9. cocos creator 中的粒子效果

    途中的粒子效果,通过plist文件和png两个文件,创建一个粒子节点,将plist文件拖入到粒子节点的file属性中,然后给custom属性打钩,把png文件拖入到texture属性中即可.

随机推荐

  1. 比较容易理解的---原生js瀑布流

    最近一直在恶补基础JS H5 CSS3的基础知识 关于这个瀑布流: 本来打算看着教程来做的. 不过 感觉理解起来有点复杂. SO, 自己参考教程默写了一个.. 目前我所接触过的瀑布流布局分为2大类 主 ...

  2. Automated Front End Test - Xvfb, Chromedriver, Selenium, Jenkins

    1. Install Xvfbm, google-chrome-stable and chromedriver in Jenkins sudo apt-get install -y xvfb goog ...

  3. 关于微信小程序遇到的wx.request({})问题

    域名请求错误问题 当我们在编写小程序,要发送请求时,wx.request({})时或许会遇到如下的问题: 一:这是因为微信小程序的开发中,域名只能是https方式请求,所以我们必须在小程序微信公众平台 ...

  4. XSS研究2-来自内部的XSS攻击的防范

    引入: 前面我们分2篇文章分别探讨了来自外部的XSS攻击和来自内部的XSS攻击,现在我们来专门探讨如何防范来自内部的XSS攻击.   实践:  http://www.cnblogs.com/crazy ...

  5. 4.docker学习之镜像

    镜像 我们知道,我们想在Windows操作系统上跑Linux,需要安装一个虚拟机程序,然后下载一个Linux镜像,在该虚拟机程序中创建一个虚拟机,并使用该镜像安装对应的Linux操作系统,安装好之后, ...

  6. SparkMLlib回归算法之决策树

    SparkMLlib回归算法之决策树 (一),决策树概念 1,决策树算法(ID3,C4.5 ,CART)之间的比较: 1,ID3算法在选择根节点和各内部节点中的分支属性时,采用信息增益作为评价标准.信 ...

  7. 消息:SQL Server 2017(vNext)的第三个公开的CTP(社区技术预览版)发布了

    今天看到了一个新闻,跟大家分享一下,有兴趣的可以去尝试一下. SQL Server 2017 CTP3于5月23日发布了,详细版本号是6.7.55.0. 大家可以去安装试试.在下载页面,目前是SQL  ...

  8. [原创]nagios搭建配置

    nagios搭建配置 一.环境 ubuntu 14.04系统 host1:172.17.0.2 serverhost2:172.17.0.3 client 二.安装 1.在两个主机上都执行一下命令: ...

  9. VR大时代-全景智慧城市搭建是一个任重而道远的任务

    全景智慧城市搭建是一个任重而道远的任务,但是也促进了实体市场的蓬勃发展与进步.VR技术改变了人们以往的娱乐方式,而全景智慧城市将会彻底改变人们的生活习惯.VR是未来的计算平台,更是人力发展历史中,技术 ...

  10. makefile介绍1.0

    1.gcc参数 -o指定生成文件名 -c只编译不链接 2.makefile标准格式 CC=gcc #编译器变量,#代表注释 SRCS=main.cpp\#源文件变量 a.cpp\ b.cpp\ c.c ...