一。基本步骤

注意:pomelo-cocos2d-jsb 没实用 https://github.com/NetEase/pomelo-cocos2d-jsb,原因这个不是最新版,另外,component根文件没有

pomelo-cocos2d-jsb 用的是 https://github.com/NetEase/chatofpomelo-websocket/tree/master/web-server/public/js/lib

这个是最新版,另外能够更新

详细步骤:

1.1下载zip文件

wget https://github.com/NetEase/chatofpomelo-websocket/archive/master.zip

1.2 拷贝lib文件夹下全部文件及文件夹到src/pomelo-cocos2d-jsb文件夹下

1.3 更新文件

component install -f && component build -v

1.4 建立index.js文件

文件内容为:

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');

看一下详细的文件夹结构

二。native 平台 相关配置:

2.1  改动project.json文件,添加"src/pomelo-cocos2d-jsb/index.js"

注意,这个文件的调用顺序也非常重要,app.js是要用到“src/pomelo-cocos2d-jsb/index.js”的

2.2 看看app.js里面怎么调用的

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 is clicked to quit the program

//    you 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 - 20,

y: 20,

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",38);

// position the label on the center of the screen

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: 180

});

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 -40)),cc.TintTo.create(2.5,255,125,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 self = 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错误');

}

});

}

});

var HelloWorldScene = cc.Scene.extend({

onEnter:function () {

this._super();

var layer = new HelloWorldLayer();

this.addChild(layer);

}

});

2.3 看看执行的日志

三。web的配置

3.1  改动project.json文件,去掉 "src/pomelo-cocos2d-jsb/index.js" 这行

3.2  改动根文件夹下的index.html 文件

改为

<!DOCTYPE html>

<html>

<head>

    <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>

</head>

<body style="padding:0; margin: 0; background: #000;">

<canvas id="gameCanvas" width="800" height="450"></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>

注意: script的调用顺序很重要,不能变动,由于有之间的调用顺序关系

3.3 执行的效果

cocos2d-js-v3.0-rc0 下 pomelo-cocos2d-jsb native web 配置的更多相关文章

  1. Centos下堡垒机Jumpserver V3.0环境部署完整记录(2)-配置篇

    前面已经介绍了Jumpserver V3.0的安装,基于这篇安装文档,下面说下Jumpserver安装后的的功能使用: 一.jumpserver的启动 Jumpserver的启动和重启 [root@t ...

  2. Cocos2D将v1.0的tileMap游戏转换到v3.4中一例(一)

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请告诉我,如果觉得不错请多多支持点赞.谢谢! hopy ;) 首先说一下为什么要转换,这是为了后面的A*寻路算法做准备.由于在 ...

  3. cocos2d js jsb XMLHttpRequest 中文乱码

    1.首先讲下怎样使用XMLHttpRequest 下面所说的是在cocos2d-x 2.2.2 或者 2.3 版本号中. 首先要明确cocos2d js事实上分两个版本号,一个是html5的版本号,另 ...

  4. cocos2d js ClippingNode 制作标题闪亮特效

    1.效果图: 之前在<Android 高仿 IOS7 IPhone 解锁 Slide To Unlock>中制作了文字上闪亮移动的效果,这次我们来看下怎样在cocos2d js 中做出类似 ...

  5. Centos下堡垒机Jumpserver V3.0环境部署完整记录(1)-安装篇

    由于来源身份不明.越权操作.密码泄露.数据被窃.违规操作等因素都可能会使运营的业务系统面临严重威胁,一旦发生事故,如果不能快速定位事故原因,运维人员往往就会背黑锅.几种常见的运维人员背黑锅场景:1)由 ...

  6. cocos2d js的一些tip

    cocos2d-js-v3.2-rc0 cc.director.end();//退出app cc.Application.getInstance().openURL("http://www. ...

  7. 高屋建瓴 cocos2d-x-3.0架构设计 Cocos2d (v.3.0) rendering pipeline roadmap(原文)

    Cocos2d (v.3.0) rendering pipeline roadmap Why (the vision) The way currently Cocos2d does rendering ...

  8. mac下搭建cocos2d-x2.2.1版本android编译环境教程

    首先我们先以引擎2.2.1为例子来新建一个TestJni的项目,来作为测试例. 创建方式如下: python create_project.py -project TestJni -package o ...

  9. 还学的动吗? 盘点下Vue.js 3.0.0 那些让人激动的功能

    转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 原文出处:https://blog.bitsrc.io/vuejs-3-0-0-beta-features- ...

随机推荐

  1. xhr的send方法以及node如何处理get和post数据

    起因:看了阮一峰老师的关于上传文件的文章,进行测试,在使用xhr对象的send方法时遇到问题. 遇到的问题是使用send方法传送过去的数据,在node后台无法接收,经过很多次测试,怀疑是不是send与 ...

  2. C#开发中遇到问题常问题

    1.C# decimal 赋值null decimal?是可空类型就是可以将值设置为Null,decimal 不能设置为null 2.var 定义变量 VAR 是3.5新出的一个定义变量的类型其实也就 ...

  3. 1.1.0-学习Opencv与MFC混合编程之---全屏截图,保存为BMP图像(并增加快捷键)

    源代码:http://download.csdn.net/detail/nuptboyzhb/3961677 Ø  添加全屏截图菜单项,菜单项的属性如下; Ø  为该菜单项建立类向导. 编辑消息处理函 ...

  4. oracle如何设置show parameter显示隐含参数

    在sqlplus中shwo parameter是显示不了隐藏参数的,需要做一个处理,如下所示:    以SYS用户登录: C:\Documents and Settings\guogang>sq ...

  5. 浅析嵌入式Linux系统的构成和启动过程

    在我们的周围,大量的嵌入式设备都是基于Linux系统来构建的,嵌入式Linux与主机Linux相比有着自己的一些特点,本文就嵌入式Linux系统的构成和启动过程做一些总结. 一.嵌入式Linux系统构 ...

  6. NLP | 自然语言处理 - 标注问题与隐马尔科夫模型(Tagging Problems, and Hidden Markov Models)

    什么是标注? 在自然语言处理中有一个常见的任务,即标注.常见的有:1)词性标注(Part-Of-Speech Tagging),将句子中的每一个词标注词性,比如名词.动词等:2)实体标注(Name E ...

  7. C#用正则表达式去掉Html中的script脚本和html标签

    原文 C#用正则表达式去掉Html中的script脚本和html标签 /// <summary>         /// 用正则表达式去掉Html中的script脚本和html标签     ...

  8. [IOS]Setting Bundle + StoryBoard

    用storyboard添加一个导航栏,其中首页有一个switch,与setting联动,还有一个button,使用modal连接另一个viewControl,其上也有一个按钮,按下销毁本viewCon ...

  9. Swift - 继承UIView实现自定义可视化组件(附记分牌样例)

    在iOS开发中,如果创建一个自定义的组件通常可以通过继承UIView来实现.下面以一个记分牌组件为例,演示了组件的创建和使用,以及枚举.协议等相关知识的学习. 效果图如下:    组件代码:Score ...

  10. mysql5.6 主从配置

    参考网址:http://www.cnblogs.com/zhoujie/p/mysql1.html http://kerry.blog.51cto.com/172631/277414/ 1.配置主库: ...