7 Star 16 Fork 6

Levil / Cocos2d-js-Module

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

#Cocos2d-js-Module

基于Cocos2d-js游戏引擎的轻量级JavaScript模块化开发解决方案。让Cocos2d-js项目拥有类似C++的#include、Lua的require的功能。

#使用方法 在Cocos2d-js项目的src文件夹中添加module.js文件,在main.js开头添加如下代码

require("src/module.js");

这样即可使用Module提供的模块化编程功能。

#API #load(name, func) 添加一个模块,第一个参数name代表模块的名称(模块名必须和文件路径保持一致,在module.js文件顶部添加了文件搜索路径"src/",所以模块名称省略掉开头的"src/"),第二个参数func是添加模块时调用的函数,func的返回值就是模块。

// Example
load("app/GameScene", function(){

var GameScene = cc.Scene.extend({});  
return GameScene;   // return the module

})

#include(name) 获取一个模块,name是该模块的名称,模块名称应该和文件路径保持一致。

// Example
var GameScene = include("app/GameScene");

#dumpModuleInfo() 打印日志,显示当前所有已经加载过的模块,方便调试。

// Example
dumpModuleInfo(); // print the loaded modules

#查看例子 理论上2.x或3.x版本的Cocos2d-js都可以使用Module。Git中Module的例子是基于Cocos2d-js 3.x版本的。

查看3.x版本例子的方法:新建一个Cocos2d-js项目,用git上的代码覆盖项目中的文件即可。

更多内容可以查看Blog: http://blog.csdn.net/levildo/article/details/44709971

下一步要修改模块代理的生成,每个模块仅生成一个代理

The MIT License (MIT) Copyright (c) 2015 Levil Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

基于Cocos2d-js游戏引擎的轻量级JavaScript模块化开发解决方案。让Cocos2d-js项目拥有类似C++的#include、Lua的require的功能。 展开 收起
JavaScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/Levil/Cocos2d-js-Module.git
git@gitee.com:Levil/Cocos2d-js-Module.git
Levil
Cocos2d-js-Module
Cocos2d-js-Module
master

搜索帮助