结构总览
js文件
src/myApp.js
src/resource.js
cocos2d.js
cocos2d-jsb.js
main.js
其他文件
build.xml
index.html

具体实现
myapp.js
var MyLayer = cc.Layer.extend(
{
isMouseDown :
false
,
helloImg :
null
,
helloLabel :
null
,
circle :
null
,
sprite :
null
,

init :
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 director the window size

var
size = cc.Director.getInstance().getWinSize();

// add a "close" icon to exit the progress. it's an autorelease object

var
closeItem = cc.MenuItemImage.create(
s_CloseNormal,
s_CloseSelected,

function
()
{
cc.log(
"close"
);
},
this
);
closeItem.setAnchorPoint(cc.p(

.

,

.

));

var
menu = cc.Menu.create(closeItem);
menu.setPosition(cc.p(

,

));

this
.addChild(menu,

);
closeItem.setPosition(cc.p(size.width -

,

));

/////////////////////////////

// 3. add your codes below...

// add a label shows "Hello World"

// create and initialize a label

this
.helloLabel = cc.LabelTTF.create(
"Hello World"
,
"Impact"
,

);

// position the label on the center of the screen

this
.helloLabel.setPosition(cc.p(size.width /

, size.height -

));

// add the label as a child to this layer

this
.addChild(
this
.helloLabel,

);

// add "Helloworld" splash screen"

this
.sprite = cc.Sprite.create(s_HelloWorld);

this
.sprite.setAnchorPoint(cc.p(

.

,

.

));

this
.sprite.setPosition(cc.p(size.width /

, size.height /

));

this
.addChild(
this
.sprite,

);
}
}
);

var
MyScene = cc.Scene.extend(
{
onEnter :
function
()
{

this
._super();

var
layer =
new
MyLayer();

this
.addChild(layer);
layer.init();
}
}
);

 
resource.js
var
s_HelloWorld =
"HelloWorld.png"
;

var
s_CloseNormal =
"CloseNormal.png"
;

var
s_CloseSelected =
"CloseSelected.png"
;

var
g_ressources = [

//image

{
src : s_HelloWorld
},
{
src : s_CloseNormal
},
{
src : s_CloseSelected
}

//plist

//fnt

//tmx

//bgm

//effect

];

 
cocos2d.js
(
function
()
{

var
d = document;

var
c =
{
COCOS2D_DEBUG :

,
//0 to turn debug off, 1 for basic debug, and 2 for full debug

box2d :
false
,
chipmunk :
false
,
showFPS :
true
,
loadExtension :
false
,
frameRate :

,
tag :
'gameCanvas'
,
//the dom element to run cocos2d on

engineDir :
'../cocos2d/'
,

//SingleEngineFile:'',

appFiles : [

'src/resource.js'
,

'src/myApp.js'

//add your own files in order here

]
};

if
(!d.createElement(
'canvas'
).getContext)
{

var
s = d.createElement(
'div'
);
s.innerHTML =
'<h2>Your browser does not support HTML5 canvas!</h2>'
+

'<p>Google Chrome is a browser that combines a minimal design with sophisticated technology to make the web faster, safer, and easier.Click the logo to download.</p>'
+

'<a href="http://www.google.com/chrome" target="_blank"><img src="http://www.google.com/intl/zh-CN/chrome/assets/common/images/chrome_logo_2x.png" border="0"/></a>'
;

var
p = d.getElementById(c.tag).parentNode;
p.style.background =
'none'
;
p.style.border =
'none'
;
p.insertBefore(s);

d.body.style.background =
'#ffffff'
;

return
;
}

window.addEventListener(
'DOMContentLoaded'
,
function
()
{

//first load engine file if specified

var
s = d.createElement(
'script'
);

/*********Delete this section if you have packed all files into one*******/


if
(c.SingleEngineFile && !c.engineDir)
{
s.src = c.SingleEngineFile;
}

else

if
(c.engineDir && !c.SingleEngineFile)
{
s.src = c.engineDir +
'platform/jsloader.js'
;
}

else

{
alert(
'You must specify either the single engine file OR the engine directory in "cocos2d.js"'
);
}

/*********Delete this section if you have packed all files into one*******/

//s.src = 'myTemplate.js'; //IMPORTANT: Un-comment this line if you have packed all files into one

d.body.appendChild(s);
document.ccConfig = c;
s.id =
'cocos2d-html5'
;

//else if single file specified, load singlefile

}
);
}
)();

 
main.js

/ this.config['frameRate']);

//load resources
cc.LoaderScene.preload(g_ressources, function ()
{
director.replaceScene(newthis.startScene());
}, this);

return true;
}
}
);

var myApp = new cocos2dApp(MyScene);

需要注意的地方

增加了资源需要手动在resource.js中添加相应的代码。

增加了js文件需要在cocos2d.js中的appfiles数组中增加相应代码。

在myApp.js文件中实现了一个Layer,并且在main.js调用了该Layer加入到启动Scene中。

在main.js中设置启动的scene,是否显示FPS,设置FrameRate,ScreenSize

cocos2d-html5模板分析的更多相关文章

  1. html5开发制作,漂亮html5模板欣赏,H5网站建设

    html5是什么? HTML5 是下一代的 HTML(超文本标记语言,网页的组成部分),HTML5是web开发世界的一次重大的改变,能适配pc.手机等各终端,跨平台性能极强,移动互联网是未来的趋势,h ...

  2. 35 个免费创新的响应式 HTML5 模板

    HTML5 和响应式都是 Web 开发领域中的热门技术,本文向你推荐 35 个免费的响应式 HTML5 模板,将两种技术完美结合. Mori responsive HTML5 Template Res ...

  3. 14个超赞的响应式HTML5模板免费下载

    现在HTML5已经势不可挡.很多朋友开始学习HTML5,当你已经学习过一些HTML5的教程之后,是不是想立即开始实战了呢?对,现在就开始吧,不过 找一些优秀的HTML5模板案例练习是相当不错的注意.当 ...

  4. 分享3一个博客HTML5模板

    1.材类别:半透明 博客html模板 个人博客 半透明html5博客主题,半透明,博客,博客html模板,个人博客,html5,灰色,半透明html5博客主题是一款适合用于个人博客主题,风格非常不错. ...

  5. HTML5模板引擎 Thymeleaf 教程(转)

    原文:http://www.open-open.com/lib/view/open1383622135586.html Thymeleaf是一个XML/XHTML/HTML5模板引擎,可用于Web与非 ...

  6. 灰色大气企业html5模板

    灰色大气企业html网页模板是一款以灰色为背景的大气简洁企业html5网站模板. 下载地址:http://www.huiyi8.com/sc/10860.html

  7. Cocos2d html5 笔记 1: overview

    昨天接触到了cocos2d-html5的的东东了, 第一次看其源代码一头雾水,幸好samples目录下面有几个例子,可以从这个入手. MoonWarriors是一个射击类的游戏, 有点像以前玩的雷电, ...

  8. 20款响应式的 HTML5 网页模板【免费下载】

    下面的列表集合了20款响应式的 HTML5 网页模板,这些专业的模板能够让你的网站吸引很多的访客.除了好看的外观,HTML5 模板吸引大家的另一个原因是由于其响应性和流动性.赶紧来看看. 您可能感兴趣 ...

  9. 20款高质量的 HTML5 网站模板【免费下载】

    下面的列表集合了20款高质量的免费 HTML5 网站模板,这些专业的模板能够让你的网站吸引很多的访客.这些免费的 HTML5 模板虽然不是响应式的,不过都很实用.赶紧来看看. 您可能感兴趣的相关文章 ...

随机推荐

  1. pygame系列_第一个程序_图片代替鼠标移动

    想想现在学校pygame有几个钟了,就写了一个小程序:图片代替鼠标移动 程序的运行效果: 当鼠标移动到窗口内,鼠标不见了,取而代之的是图片..... ========================= ...

  2. javascript小记-作用域

    一.全局作用域 全局作用域的变量不论在什么时候都可以直接引用,而不必通过全局对象:满足以下条件的变量属于全局作用域:1.在最外层定义的变量2.全局对象的属性3.任何地方隐式定义的变量(未定义直接赋值的 ...

  3. MAX II Device Compatibility with 5.0-V CMOS Devices

    http://www.altera.com/literature/hb/max2/max2_mii51009.pdf The open-drain pin never drives high, onl ...

  4. Openfire 服务器更换ip后的恢复方法

    如果你的服务器名称和mysql的地址都是使用的静态ip地址配置的,更改ip后,openfire就会开启失败,这种情况下请看下面的解决方法. 比如你的ip地址由 192.168.0.111 改为192. ...

  5. Nginx HTTP负载均衡/反向代理的相关参数测试

    原文地址:http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/03/15/1984976.html 测试目的 (1)弄清楚HTTP Upstr ...

  6. SpreadSheet数据导出为DataTable z

    devexpress也提供了一种将excel数据,而且可以指定区域进行转换,用起来相当灵活,本人将其解决方法分享如下(代码):          private DataTable export(Wo ...

  7. VS2010 打包生成exe文件后 执行安装文件出现 TODO:&lt;文件说明&gt;已停止工作并已关闭

    一.VS2010 打包生成exe文件后  执行安装文件出现  TODO:<文件说明>已停止工作并已关闭 TODO: <文件说明>已停止工作 原因: 打包的时候在文件系统中建立了 ...

  8. js获取本机mac地址,IP地址,计算机名

    <!DOCTYPE HTML> <html> <head> <title>js获取本机mac地址,IP地址,计算机名</title> < ...

  9. TQ2440实现触摸屏和qt图形 解决segmentation fault

    使用触摸屏,首先安装触摸屏矫正程序. 下载并解压tslib-1.4,进入主文件夹,运行: 1 [root@localhost ~]#./autogen.sh 2 [root@localhost ~]# ...

  10. git打pach包

    在开发中,我们发出的基线版本号常常会有一些bug须要修复,假设採用本地上库,然后再给用户新的版本号,可能会费时费力,而假设给用户我们改动后的代码让用户一行一行合入本地,也显的比較落后,假设用户那边也使 ...