├── .cocos-project.json
├── .gitignore
├── .gitmodules
├── .project
├── .settings
└── version.json
├── README.md
├── config.json
├── fileinfo_debug.json
├── index.html
├── main.js
├── project.json
├── res
├── CloseNormal.png
├── CloseSelected.png
├── HelloWorld.png
└── favicon.ico
└── src
├── app.js
└── resource.js
/.cocos-project.json:
--------------------------------------------------------------------------------
1 | {
2 | "has_native": true,
3 | "project_type": "js",
4 | "assets": {
5 | "ignores": []
6 | }
7 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | frameworks/
2 | runtime/
3 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "pomelo-cocos2d-js"]
2 | path = pomelo-cocos2d-js
3 | url = https://github.com/NetEase/pomelo-cocos2d-js
4 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | testPomelo
4 |
5 |
6 |
7 |
8 |
9 |
10 | org.ccdt.cocosproject
11 | org.ccdt.jsdt.core.jsNature
12 |
13 |
14 | 1.2
15 |
16 |
17 |
--------------------------------------------------------------------------------
/.settings/version.json:
--------------------------------------------------------------------------------
1 | {
2 | "ideVersion": "v1.0.0.RC0",
3 | "templateVersion": "1.2",
4 | "runtimeVersion": "1.2",
5 | "engineVersion": "cocos2d-x 3.2alpha0"
6 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | pomelo-cocos2d-js-demo
2 | ======================
3 |
4 | cocos2d-js 是整合了 cocos2d-html5 和 cocos2d-jsb,可以方便的开发部署到各种设备环境中
5 | pomelo-cocos2d-js 则是对 pomelo-client-websocket 和 pomelo-cocos2d-jsb 的整合
6 |
7 | 本文以cocos code ide为开发环境说明如何搭建 pomelo 与 cocos2d-js 的开发环境
8 |
9 | 1:下载 cocos code ide
10 | [cocos code ide](http://cocos2d-x.org/download)
11 |
12 | 2:下载 cocos2d-js 配置cocos code ide
13 | [cocos code ide](http://cocos2d-x.org/download)
14 | [cocos_code_ide环境配置](http://www.cocos2d-x.org/wiki/Cocos_Code_IDE)
15 |
16 | 3:新建 cocos javascript project
17 | 
18 |
19 | 这个时候,可以点击 build runtime 按钮,看是否能够成功编译
20 | 可以选择 win32 runtime(本文演示的是win32) 或者 android runtime
21 | 
22 |
23 | 4:下载 pomelo-cocos2d-js
24 | 在项目根路径下面执行
25 | ```
26 | git clone https://github.com/Netease/pomelo-cocos2d-js.git --recursive
27 | ```
28 |
29 | 5:cocos2d-html5 环境搭建
30 | 修改index.html
31 | ```
32 |
33 |
34 |
37 |
38 | ```
39 |
40 | 6:cocos2d-jsb 环境搭建
41 | 修改main.js
42 | ```
43 | cc.game.onStart = function() {
44 | if (cc.sys.isNative === true) {
45 | require('pomelo-cocos2d-js/index.js');
46 | }
47 |
48 | cc.view.setDesignResolutionSize(800, 450, cc.ResolutionPolicy.EXACT_FIT);
49 | cc.view.resizeWithBrowserSize(true);
50 | // load resources
51 | cc.LoaderScene.preload(g_resources, function() {
52 | cc.director.runScene(new HelloWorldScene());
53 | }, this);
54 | };
55 | cc.game.run();
56 | ```
57 |
58 | 7:测试chat
59 | 修改app.js,添加
60 | ```
61 | var pomeloChat = function() {
62 | var pomelo = window.pomelo;
63 |
64 | var route = 'gate.gateHandler.queryEntry';
65 | var uid = "uid";
66 | var rid = "rid";
67 | var username = "username";
68 |
69 | pomelo.init({
70 | host: "127.0.0.1",
71 | port: 3014,
72 | log: true
73 | }, function() {
74 | pomelo.request(route, {
75 | uid: uid
76 | }, function(data) {
77 | pomelo.disconnect();
78 | pomelo.init({
79 | host: data.host,
80 | port: data.port,
81 | log: true
82 | }, function() {
83 | var route = "connector.entryHandler.enter";
84 | pomelo.request(route, {
85 | username: username,
86 | rid: rid
87 | }, function(data) {
88 | cc.log(JSON.stringify(data));
89 | chatSend();
90 | });
91 | });
92 | });
93 | });
94 |
95 | function chatSend() {
96 | var route = "chat.chatHandler.send";
97 | var target = "*";
98 | var msg = "msg"
99 | pomelo.request(route, {
100 | rid: rid,
101 | content: msg,
102 | from: username,
103 | target: target
104 | }, function(data) {
105 | cc.log(JSON.stringify(data));
106 | });
107 | }
108 | }
109 |
110 | ```
111 |
112 | 然后在 HelloWorldLayer 的 ctor 里面添加
113 | ```
114 | pomeloChat();
115 | ```
116 |
117 | 8:本地把chatofpomelo-websocket跑起来
118 |
119 | 9:分别在jsb环境和html5环境测试
120 | 
121 | 
122 |
123 |
124 | 注意:该项目只做代码相关演示, cocos2d-js 相关库并没有上传
125 | 项目下载
126 | ```
127 | git clone https://github.com/pomelonode/pomelo-cocos2d-js-demo.git --recursive
128 | ```
--------------------------------------------------------------------------------
/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "init_cfg": {
3 | "isLandscape": true,
4 | "name": "testPomelo",
5 | "width": 960,
6 | "height": 640,
7 | "entry": "main.js",
8 | "consolePort": 0,
9 | "debugPort": 0
10 | },
11 | "simulator_screen_size": [
12 | {
13 | "title": "iPhone 3Gs (480x320)",
14 | "width": 480,
15 | "height": 320
16 | },
17 | {
18 | "title": "iPhone 4 (960x640)",
19 | "width": 960,
20 | "height": 640
21 | },
22 | {
23 | "title": "iPhone 5 (1136x640)",
24 | "width": 1136,
25 | "height": 640
26 | },
27 | {
28 | "title": "iPad (1024x768)",
29 | "width": 1024,
30 | "height": 768
31 | },
32 | {
33 | "title": "iPad Retina (2048x1536)",
34 | "width": 2048,
35 | "height": 1536
36 | },
37 | {
38 | "title": "Android (800x480)",
39 | "width": 800,
40 | "height": 480
41 | },
42 | {
43 | "title": "Android (854x480)",
44 | "width": 854,
45 | "height": 480
46 | },
47 | {
48 | "title": "Android (1280x720)",
49 | "width": 1280,
50 | "height": 720
51 | },
52 | {
53 | "title": "Android (1920x1080)",
54 | "width": 1920,
55 | "height": 1080
56 | }
57 | ]
58 | }
--------------------------------------------------------------------------------
/fileinfo_debug.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Cocos2d-html5 Hello World test
6 |
7 |
8 |
9 |
10 |
11 |
12 |
21 |
22 |
23 |
24 |
25 |
26 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/main.js:
--------------------------------------------------------------------------------
1 | cc.game.onStart = function() {
2 | if (cc.sys.isNative === true) {
3 | require('pomelo-cocos2d-jsb/index.js');
4 | }
5 |
6 | cc.view.setDesignResolutionSize(800, 450, cc.ResolutionPolicy.EXACT_FIT);
7 | cc.view.resizeWithBrowserSize(true);
8 | // load resources
9 | cc.LoaderScene.preload(g_resources, function() {
10 | cc.director.runScene(new HelloWorldScene());
11 | }, this);
12 | };
13 | cc.game.run();
--------------------------------------------------------------------------------
/project.json:
--------------------------------------------------------------------------------
1 | {
2 | "project_type": "javascript",
3 |
4 | "debugMode" : 1,
5 | "showFPS" : true,
6 | "frameRate" : 60,
7 | "id" : "gameCanvas",
8 | "renderMode" : 2,
9 | "engineDir":"frameworks/cocos2d-html5",
10 |
11 | "modules" : ["menus"],
12 |
13 | "jsList" : [
14 | "src/resource.js",
15 | "src/app.js"
16 | ]
17 | }
18 |
--------------------------------------------------------------------------------
/res/CloseNormal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pomelonode/pomelo-cocos2d-js-demo/3b14b69e426459d767f1cdb2fac42bd25e12879f/res/CloseNormal.png
--------------------------------------------------------------------------------
/res/CloseSelected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pomelonode/pomelo-cocos2d-js-demo/3b14b69e426459d767f1cdb2fac42bd25e12879f/res/CloseSelected.png
--------------------------------------------------------------------------------
/res/HelloWorld.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pomelonode/pomelo-cocos2d-js-demo/3b14b69e426459d767f1cdb2fac42bd25e12879f/res/HelloWorld.png
--------------------------------------------------------------------------------
/res/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pomelonode/pomelo-cocos2d-js-demo/3b14b69e426459d767f1cdb2fac42bd25e12879f/res/favicon.ico
--------------------------------------------------------------------------------
/src/app.js:
--------------------------------------------------------------------------------
1 |
2 | var HelloWorldLayer = cc.Layer.extend({
3 | isMouseDown:false,
4 | helloImg:null,
5 | helloLabel:null,
6 | circle:null,
7 | sprite:null,
8 |
9 | ctor:function () {
10 | //////////////////////////////
11 | // 1. super init first
12 | this._super();
13 |
14 | /////////////////////////////
15 | // 2. add a menu item with "X" image, which is clicked to quit the program
16 | // you may modify it.
17 | // ask director the window size
18 | var size = cc.director.getWinSize();
19 |
20 | // add a "close" icon to exit the progress. it's an autorelease object
21 | var closeItem = cc.MenuItemImage.create(
22 | res.CloseNormal_png,
23 | res.CloseSelected_png,
24 | function () {
25 | cc.log("Menu is clicked!");
26 | },this);
27 | closeItem.attr({
28 | x: size.width - 20,
29 | y: 20,
30 | anchorX: 0.5,
31 | anchorY: 0.5
32 | });
33 |
34 | var menu = cc.Menu.create(closeItem);
35 | menu.x = 0;
36 | menu.y = 0;
37 | this.addChild(menu, 1);
38 |
39 | /////////////////////////////
40 | // 3. add your codes below...
41 | // add a label shows "Hello World"
42 | // create and initialize a label
43 | this.helloLabel = cc.LabelTTF.create("Hello World", "Arial", 38);
44 | // position the label on the center of the screen
45 | this.helloLabel.x = size.width / 2;
46 | this.helloLabel.y = 0;
47 | // add the label as a child to this layer
48 | this.addChild(this.helloLabel, 5);
49 |
50 | var lazyLayer = cc.Layer.create();
51 | this.addChild(lazyLayer);
52 |
53 | // add "HelloWorld" splash screen"
54 | this.sprite = cc.Sprite.create(res.HelloWorld_png);
55 | this.sprite.attr({
56 | x: size.width / 2,
57 | y: size.height / 2,
58 | scale: 0.5,
59 | rotation: 180
60 | });
61 | lazyLayer.addChild(this.sprite, 0);
62 |
63 | var rotateToA = cc.RotateTo.create(2, 0);
64 | var scaleToA = cc.ScaleTo.create(2, 1, 1);
65 |
66 | this.sprite.runAction(cc.Sequence.create(rotateToA, scaleToA));
67 | this.helloLabel.runAction(cc.Spawn.create(cc.MoveBy.create(2.5, cc.p(0, size.height - 40)),cc.TintTo.create(2.5,255,125,0)));
68 |
69 | pomeloChat();
70 | return true;
71 | }
72 | });
73 |
74 | var HelloWorldScene = cc.Scene.extend({
75 | onEnter:function () {
76 | this._super();
77 | var layer = new HelloWorldLayer();
78 | this.addChild(layer);
79 | }
80 | });
81 |
82 | var pomeloChat = function() {
83 | var pomelo = window.pomelo;
84 |
85 | var route = 'gate.gateHandler.queryEntry';
86 | var uid = "uid";
87 | var rid = "rid";
88 | var username = "username";
89 |
90 | pomelo.init({
91 | host: "10.240.157.76",
92 | port: 3014,
93 | log: true
94 | }, function() {
95 | pomelo.request(route, {
96 | uid: uid
97 | }, function(data) {
98 | pomelo.disconnect();
99 | pomelo.init({
100 | host: data.host,
101 | port: data.port,
102 | log: true
103 | }, function() {
104 | var route = "connector.entryHandler.enter";
105 | pomelo.request(route, {
106 | username: username,
107 | rid: rid
108 | }, function(data) {
109 | cc.log(JSON.stringify(data));
110 | chatSend();
111 | });
112 | });
113 | });
114 | });
115 |
116 | function chatSend() {
117 | var route = "chat.chatHandler.send";
118 | var target = "*";
119 | var msg = "msg"
120 | pomelo.request(route, {
121 | rid: rid,
122 | content: msg,
123 | from: username,
124 | target: target
125 | }, function(data) {
126 | cc.log(JSON.stringify(data));
127 | });
128 | }
129 | }
130 |
--------------------------------------------------------------------------------
/src/resource.js:
--------------------------------------------------------------------------------
1 | var res = {
2 | HelloWorld_png : "res/HelloWorld.png",
3 | CloseNormal_png : "res/CloseNormal.png",
4 | CloseSelected_png : "res/CloseSelected.png"
5 | };
6 |
7 | var g_resources = [
8 | //image
9 | res.HelloWorld_png,
10 | res.CloseNormal_png,
11 | res.CloseSelected_png
12 |
13 | //plist
14 |
15 | //fnt
16 |
17 | //tmx
18 |
19 | //bgm
20 |
21 | //effect
22 | ];
--------------------------------------------------------------------------------