1.使用pomelo init 命令创建pomelo工程,并用pomelo start 命令启动后端。
2.使用cocos 创建工程,framework3.8,工程名hellopomelo。
3.进入hellopomelo,下载git clone https://github.com/NetEase/pomelo-cocos2d-js.git 到此目录
4.在project.json 中的jsList中加入"pomelo-cocos2d-js/dist/pomelo-cocos2d-js.js"
5.修改app.js如下:
var HelloWorldLayer = cc.Layer.extend({
sprite:null,
ctor:function () {
//////////////////////////////
// 1. super init first this._super()
/////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the program
// you may modify it.
// ask the window size
var size = cc.winSize;
var mainscene = ccs.load(res.MainScene_json);
this.addChild(mainscene.node);
//var dTTF = new cc.LabelTTF("aaaaaaaaa","Helvetica",20);
//dTTF.setPosition(cc.p(winsize.width/2,winsize.height/2));
//this.addChild(dTTF);
var pomelo = window.pomelo;
var host = "127.0.0.1";
var port = "3010";
var hInfo = {host: host,port: port,log: true};
var cbFun = function()
{
var fun = function (data)
{
//alert(data.msg);
cc.log(JSON.stringify(data.msg));
var winsize = cc.winSize;
var dTTF = new cc.LabelTTF("aaaaaaaaa","Helvetica",20);
dTTF.setPosition(cc.p(winsize.width/2,winsize.height/2));
this.addChild(dTTF);
}
pomelo.request("connector.entryHandler.entry", "hello pomelo", fun);
};
pomelo.init(hInfo,cbFun);
return true;
}
});
6.运行,控制台输出如下
上午1038 debugger: Cocos Code IDE
上午1038 add searching path:
上午1038 Console: listening on 0.0.0.0 : 6050
上午1038 Console: listening on 0.0.0.0 : 6060
上午1038 ------------------------------------------------
上午1038 LOAD Js FILE: main.js
上午1038 ------------------------------------------------
上午1038 JS: connect to ws://127.0.0.1:3010
上午1038 _host: 127.0.0.1, _port: 3010, _path: /
上午1038 NOTICE: Initial logging level 7
上午1038 NOTICE: Library version: 1.3 762deb8
上午1038 NOTICE: IPV6 compiled in and enabled
上午1038 NOTICE: libev support not compiled in
上午1038 NOTICE: static allocation: 4496 + (16 x 10240 fds) = 168336 bytes
上午1038 NOTICE: canonical_hostname = zhangsandeMacBook-Pro.local
上午1038 NOTICE: per-conn mem: 184 + 1594 headers + protocol rx buf
上午1038 JS: “game server is ok.”
上午1038 ERROR
JS:/Users/zhangsan/Documents/projects/hellopomelo/src/app.js:36:TypeError:this.addChild is not a function /Users/zhangsan/Documents/projects/hellopomelo/src/app.js
在连接成功后的回调中用this.addCihld()出错,怎么处理?