Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加一个简单的自动更新程序 #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions helloWorld/HelloWorld.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var HelloWorld = cc.Scene.extend({
onEnter:function(){
this._super();
var winSize = cc.visibleRect;
//从flax输出的素材文件中,创建id为anim的动画,对应flash库中链接名为mc.anim的动画
//添加到this中,并设置位置为舞台中心
var anim = flax.assetsManager.createDisplay(res.anim, "helloWorld", {parent: this, x: winSize.width/2, y: winSize.height/2});
//在最后一帧停住
anim.autoStopWhenOver = true;
//从当前帧就是第1帧开始播放
anim.play();
#code#
}
});
2 changes: 2 additions & 0 deletions helloWorld/autoUpdate.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node autoUpdate.js
cocos run -p web --port 8888
38 changes: 38 additions & 0 deletions helloWorld/autoUpdate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
var fs = require('fs');
var resTpl=fs.readFileSync("resource.tpl", "utf-8");
var HelloWorldTpl=fs.readFileSync("HelloWorld.tpl", "utf-8");
var codeTpl=fs.readFileSync("code.tpl", "utf-8");
String.prototype.endsWith = function(suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
function filterJsonOrPlist(str, index, array){
if(str=="flaxAnim.plist")return false;
if(str.endsWith(".json")||str.endsWith(".plist"))return true;
return false;
}
function getFilenameNoSuffix(str){
if(str.endsWith(".json"))return str.substr(0,str.length-5);
if(str.endsWith(".plist"))return str.substr(0,str.length-6);
return str;
}
fs.readdir("./res",function(err, files){
//console.log(files);
var plistFiles=files.filter(filterJsonOrPlist);
console.log(plistFiles);
var res1='',res2='',code='';
for(var i=0;i<plistFiles.length;i++){
var animName=getFilenameNoSuffix(plistFiles[i]);
res1+=',\n'+animName+':"res/'+animName+'.plist",\n';
res1+=animName+'_png:"res/'+animName+'.png"';
res2+=',\n'+'res.'+animName+',\n';
res2+='res.'+animName+'_png';
code+=codeTpl.replace(new RegExp("#name#","gm"),animName);
}
var res=resTpl.replace("#res1#",res1);
res=res.replace("#res2#",res2);
console.log(res);
fs.writeFileSync("./src/resource.js",res,"utf-8");
var helloWorld=HelloWorldTpl.replace("#code#",code);
console.log(helloWorld);
fs.writeFileSync("./src/HelloWorld.js",helloWorld,"utf-8");
})
4 changes: 4 additions & 0 deletions helloWorld/code.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var #name# = flax.assetsManager.createDisplay(res.#name#, "#name#", {parent: this, x: winSize.width/2, y: winSize.height/2});
#name#.autoStopWhenOver = true;
#name#.setAutoPlayChildren(true);
#name#.play();
11 changes: 11 additions & 0 deletions helloWorld/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
用法:

1、通过flax工具,将flash目录的swf文件转到res目录后,
2、运行autoUpdate.bat将自动做如下事情:
2.1 自动遍历res目录的.plist和.json文件。
2.2 自动修改src/resource.js和src/HelloWorld.js
上两步通过node autoUpdate.js实现。
2.3 自动启动web服务器并打开游戏。
这一步cocos run -p web --port 8888

一般如果把cocos项目放到目录,可以不用运行bat文件,直接运行node autoUpdate.js即可。
9 changes: 9 additions & 0 deletions helloWorld/resource.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var res = {
anim:"res/flaxAnim.plist",
anim_png:"res/flaxAnim.png"#res1#
};

var res_helloWorld = [
res.anim,
res.anim_png#res2#
];
1 change: 1 addition & 0 deletions src/flax/core/InputManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ flax.InputManager = cc.Node.extend({
removeListener:function(target, func, type)
{
if(target == null) target = this;
type = (type == null) ? InputType.click : type;
var calls = this._callbacks[target.__instanceId];
if(calls && (type == null || (type != InputType.keyPress && type != InputType.keyUp))) {
// this.scheduleOnce(function(){
Expand Down