The company has a project is COCOS2D-HTML5, followed by a little, to cocos or very interested, holding an art more than the attitude of the body began to learn cocos, here I study is cocos2d-js, mainly I started to look at the time has been called JS did not call HTML5, In fact, Cocos2d-js is the combination of HTML5 and js-binding, because now the work is also written JS so there is a great interest in JS. Here is the main record of my study and use of COCOS2D-JS process, compared to my memory is not particularly good.
1. First, you can go to the official website to download COCOS2D-JS, address: http://www.cocos2d-x.org/download, here in fact, there is a Chinese version of the site, but not all stations are Chinese, only part of the download:
But I download the time is still V3.0 RC1, now have to 2, also one weeks of time, update is very fast, click to download on the line,
2. After download, put in the new folder cocos, such as:
3. In order to facilitate the use of the best is to set the environment variables, or each use of input a large string of paths is too inconvenient,
1 sudo
Open with Vim, then set the environment variable in it: At the bottom, add the following code,
1 export path=/users/dn9x/cocos/cocos2d-js-v3. 0-rc1/tools/cocos2d-console/bin: $PATH
Press ECS to exit the edit state: wq! exit, then close the terminal, then reopen the terminal.
4. Enter cocos-h in the terminal at this time to see if it is normal.
1bogon:~ dn9x$ Cocos-h2 3/users/dn9x/cocos/cocos2d-js-v3.0-rc1/tools/cocos2d-console/bin/cocos.py0.7-Cocos console:a Command line tool forcocos2d4 5 Available Commands:6Run compiles & deploy project and Thenruns it on the target7Luacompile minifies and/or compiles LUA files8 deploy deploy a project to the target9 compile compiles the current project to binaryTen New creates a new project OneJscompile minifies and/or compiles JS files A - Available arguments: --H,--Help Show This help information the-V,--version Show The version of this command tool - - Example: -/users/dn9x/cocos/cocos2d-js-v3.0-rc1/tools/cocos2d-console/bin/cocos.py New-- Help +/users/dn9x/cocos/cocos2d-js-v3.0-rc1/tools/cocos2d-console/bin/cocos.py Run-- Help -bogon:~ dn9x$
This information shows that the project is already ready for COCOS2D-JS development, the current COCOS2D-JS is created and run through the command line, the next introduction of the new project, mainly to step-by-step, where to use where to introduce, enter Cocos new-h View new Help:
1bogon:~ dn9x$ Cocos New-h2Usage:cocos new [-h] [-P package_name]-l {CPP, Lua,js} [-D DIRECTORY]3[-T Template_name] [--ios-Bundleid Ios_bundleid]4[--mac-bundleid Mac_bundleid] [--no-Native]5 [PROJECT_NAME]6 7 creates a new project8 9 positional arguments:Ten Project_Name Set the PROJECT NAME One A Optional arguments: --H,--Help show this help message and exit --P package_name,--Package Package_name theSet a package name forProject --L {CPP, Lua,js},--language {CPP, Lua,js} - Major programming language you want to use, should be -[CPP| Lua |JS] +-D DIRECTORY,--Directory directory -Set Generate project Directory forProject +-T Template_name,--template Template_name A Set The template name want create from at--ios-Bundleid Ios_bundleid -Set a bundleID foriOS Project ---mac-Bundleid Mac_bundleid -Set a bundleID forMac Project - -lua/JS Project arguments: in--no-native No native support. -bogon:~ dn9x$
This is actually very clear,
1 -l to use the language, mainly CPP, Lua, JS, here is the JS2 -p package name, such as Com.dn9x.wan3 -D Project New location
5. Create a new project here, such as the name HelloC1, such as: note the directory here, I have work/study/under the new directory Cocos, all the Cocos of the project will be placed here,
1Bogon:cocos dn9x$ Cocos New Helloc1-l js-p com.dn9x.helloc1-d.2 Running command:new3> Copy Template into/users/dn9x/work/study/cocos/HelloC14> Copying cocos2d-HTML5 files ...5>Copying files from template directory ...6>Copying directory from Cocos root directory ...7> Copying cocos2d-x Files ...8> Rename project name from'Hellojavascript'To'HelloC1'9> Replace the project name from'Hellojavascript'To'HelloC1'Ten> Replace the project package name from'Org.cocos2dx.hellojavascript'To'Com.dn9x.helloc1' OneBogon:cocos dn9x$
A new COCOS2D-JS project has been created here, generally we write the code is now in the browser test writing, when the project is completed and compiled into the various platform of the app, so first you want to let the project in the browser to run up,
6. Start the project, the Mac platform will install Apache by default, so it is convenient to edit the Apache configuration file:
1 sudo vim/etc/apache2/extra/httpd-vhosts.conf
Add the following code at the bottom:
1Listen80922<virtualhost *:8092>3DocumentRoot"/users/dn9x/work/study/cocos"4 ServerName localhost5Errorlog"/private/var/log/apache2/sites-error_log"6Customlog"/private/var/log/apache2/sites-access_log"Common7<Directory/Users/dn9x>8 Options Indexes followsymlinks multiviews9 allowoverride NoneTen Order Deny,allow One allow from all A</Directory> -</VirtualHost>
Here you have to configure according to your own path, if there is a problem can be Baidu query, here is not necessarily to use Apache, if you have other servers can also be configured.
7. Restart the service
1 sudo apachectl restart
8. Enter Localhost:8092/helloc1 in the browser to see the effect.
9. Here you can write Cocos code, in fact, Cocos is still very cow fork, our company's project to write a code, release time Android, IOS, Web,chrome app are compiled, so really great, but there are shortcomings is not particularly good localization, Although you can compile cheer Android app, but it is not as good as Android, but this may be a future direction, one encoding multi-platform compilation run.
10. The next article will cover the compilation of Cheer Android and iOS app running,
Cocos2d-js:1. Environment Construction