Cocos2d-html5 通过apache ant编译成web应用以便部署到服务器

Cocos2d-html5项目编译
本文详细介绍了如何在MacOSX环境下使用Apache Ant工具进行Cocos2d-html5项目的编译流程,包括配置build.xml文件、执行编译命令及修改cocos2d.js文件等步骤。

勤奋努力,持之以恒!


开发环境:
Mac OSX 10.9.3

Cocos2d-html5-v2.2.3

如何在Mac上安装apache ant ,请移步至:http://blog.youkuaiyun.com/song_hui_xiang/article/details/14315529


我的HeroUpUp-Html5项目的目录结构如下图:



1.打开项目中的build.xml文件,把项目中src目录下的所有js文件添加到build.xml的<sourcesdir="${basedir}">下:

<sources dir="${basedir}">
                <file name="src/resource.js"/>
                <file name="src/Game.js"/>
                <file name="main.js"/>
                <file name="src/EachPlate.js"/>
                <file name="src/EachTool.js"/>
                <file name="src/HeroRole.js"/>
                <file name="src/PlateTenTool.js"/>
                <file name="src/Utilities.js"/>
            </sources>

在build.xml文件中有这么一条语句:debug="false"output="myTemplate.js">,myTemplate.js是通过ant编译成的js文件的名字。

在此我使用默认的名字,也就是myTemplate.js这个名字。


2.打开终端,cd到build.xml目录,输入命令 ant 回车如下图表示编译成功。



这样在你的项目目录下会多出myTemplate.js这么一个文件,这就是我们编译好的js文件。


3.打开项目中的cocos2d.js文件,找到window.addEventListener 方法,看其中cocos给的官方解释,想必你就懂得怎么做了。所以修改如下:

window.addEventListener('DOMContentLoaded', fn = function () {
        this.removeEventListener('DOMContentLoaded', fn, false);
        //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 + '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
    });

经过以上三步整个编译就完成了,然后只需要将res资源文件夹cocos2d.jsindex.htmlmyTemplate.js放到网站上就可以了。





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值