One. Basic steps
Note: POMELO-COCOS2D-JSB does not use HTTPS://GITHUB.COM/NETEASE/POMELO-COCOS2D-JSB, because this is not the latest version, in addition, the component root file does not
POMELO-COCOS2D-JSB used a https://github.com/NetEase/chatofpomelo-websocket/tree/master/web-server/public/js/lib.
This is the latest version and can be updated
Specific steps:
1.1 Download ZIP file
wget Https://github.com/NetEase/chatofpomelo-websocket/archive/master.zip
1.2 Copy all files and directories under the Lib directory into the SRC/POMELO-COCOS2D-JSB directory
1.3 Update files
Component Install-f && component Build-v
1.4 Setting up Index.js files
The contents of the file are:
var window = window | | {};
var module = Module | | {};
Module.exports = {};
var console = cc;
Console.error = Cc.log;
var setTimeout = function (fn, interval) {
var instance = cc. Director.getinstance ();
var scene = Instance.getrunningscene ();
Instance.getscheduler ().
Schedulecallbackfortarget (Scene, FN, interval, 1, 0, false);
return scene;
}
var cleartimeout = function (target) {
var instance = cc. Director.getinstance ();
Instance.getscheduler (). Unscheduleallcallbacksfortarget (target);
}
Window.settimeout = SetTimeout;
Window.cleartimeout = cleartimeout;
Require (' src/pomelo-cocos2d-jsb/components/component-emitter/index.js ');
Window. Eventemitter = Emitter;
Require (' src/pomelo-cocos2d-jsb/components/netease-pomelo-protocol/lib/protocol.js ');
Require (' src/pomelo-cocos2d-jsb/components/pomelonode-pomelo-protobuf/lib/client/protobuf.js ');
Require (' src/pomelo-cocos2d-jsb/components/pomelonode-pomelo-jsclient-websocket/lib/pomelo-client.js ');
Look at the specific directory structure
Two. Native platform-related configuration:
2.1 Modify the Project.json file to add "Src/pomelo-cocos2d-jsb/index.js"
Note that the order of invocation of this file is also important, app.js is to use the "Src/pomelo-cocos2d-jsb/index.js"
2.2 See how the app.js inside.
var pomelo = Window.pomelo;
var Helloworldlayer = cc. Layer.extend ({
Sprite:null,
ctor:function () {
//////////////////////////////
//1. Super Init first
this. _super ();
this. CONNECT2SVR ();
/////////////////////////////
//2. Add a menu item with "X" image, which are clicked to quit the program
//May modify it.
//Ask Director the window size
var size = Cc.director.getWinSize ();
//Add a "close" icon to exit the progress. It ' s an Autorelease object
var closeitem = cc. Menuitemimage.create (
Res. Closenormal_png,
Res. Closeselected_png,
function () {
Cc.log ("menu is clicked!");
}, this);
Closeitem.attr ({
X:size.width-
Y:
Anchorx: 0.5,
Anchory: 0.5
});
var menu = cc. Menu.create (Closeitem);
menu.x = 0;
Menu.y = 0;
this. AddChild (menu, 1);
/////////////////////////////
//3. Add your codes below ...
//Add a label shows "Hello World"
//Create and initialize a label
var hellolabel = cc. Labelttf.create ("Hello World","Arial",$);
//Position the label on the center of the
hellolabel.x = size.width/ 2;
Hellolabel.y = 0;
//Add the label as a child to this layer
this. AddChild (Hellolabel, 5);
//Add "HelloWorld" splash screen "
this. Sprite = cc. Sprite.create (Res. Helloworld_png);
//this.sprite = cc. Sprite.create (grasspng);
this. Sprite.attr ({
X:size.width/ 2,
Y:size.height/ 2,
Scale: 0.5,
Rotation:
});
this. AddChild (this. Sprite,0);
var rotatetoa = cc. Rotateto.create (2,0);
var scaletoa = cc. Scaleto.create (2,1,1);
this. sprite.runaction (CC. Sequence.create (Rotatetoa, Scaletoa));
Hellolabel.runaction (CC. Spawn.create (CC. Moveby.create (2.5, CC.P (0, Size.Height-)), CC. Tintto.create (2.5,255,0)));
return true;
},
Connect2svr: function() {
Pomelo.init ({
Host: ' 127.0.0.1 ',
Port: 3014,
LOG: true
}, function() {
var route =' gate.gateHandler.queryEntry ';
Pomelo.request (route, {}, function(data) {
Pomelo.disconnect ();
Pomelo.init ({
Host:data.host,
Port:data.port,
LOG: true
}, function() {});
});
});
},
Loginsvr: function() {
var = this ;
var gplayername = ' name ';
var password = ' Pass ';
Password = MD5 (password);
//self.mtips.setstring (");
route = "Connector.entryHandler.loginSvr";
Pomelo.request (Route, {
Playername:gplayername,
Password:password
}, function(data) {
if (Data.ret) {
//gplayerid = Data.playerid;
//var nextscene = cc. Scene.create ();
//ggamelobbylayer = new Gamelobbylayer ();
//nextscene.addchild (Ggamelobbylayer);
//cc. Director.getinstance (). Replacescene (CC. Transitionslideinr.create (1, nextscene));
} Else {
//self.mtips.setstring (' password error ');
}
});
}
});
var Helloworldscene = cc. Scene.extend ({
OnEnter:function () {
this. _super ();
var layer = new helloworldlayer ();
this. AddChild (layer);
}
});
2.3 Look at the running log
Three. Configuration of the Web
3.1 Modify the Project.json file to remove the "src/pomelo-cocos2d-jsb/index.js" line
3.2 Modifying the index.html file under the root directory
Switch
<! DOCTYPE html>
<meta charset= "Utf-8" >
<TITLE>COCOS2D-HTML5 Hello World test</title>
<link rel= "icon" type= "Image/gif" href= "Res/favicon.ico"/>
<meta name= "apple-mobile-web-app-capable" content= "yes"/>
<meta name= "Full-screen" content= "yes"/>
<meta name= "Screen-orientation" content= "Portrait"/>
<meta name= "X5-fullscreen" content= "true"/>
<meta name= "360-fullscreen" content= "true"/>
<style>
Body, canvas, div {
-moz-user-select:none;
-webkit-user-select:none;
-ms-user-select:none;
-khtml-user-select:none;
-webkit-tap-highlight-color:rgba (0, 0, 0, 0);
}
</style>
<body style= "padding:0; margin:0; Background: #000; " >
<canvas id= "Gamecanvas" width= "height=" ></canvas>
<script src= "Frameworks/cocos2d-html5/ccboot.js" ></script>
<script src= "Src/pomelo-cocos2d-jsb/build/build.js" ></script>
<script type= "Text/javascript" >
Require (' boot ');
</script>
<script src= "Main.js" ></script>
</body>
Note: The order of the script calls is very important and cannot be changed because there is a sequential relationship between calls
3.3 Effect of running