[One of Cocos2d-HTML5 Development] HTML5 project and briefly describe the relationship with cocos2d/x Engine

Source: Internet
Author: User

This site is originally written by Li huaming Himi. The reposted post must clearly indicate: Author: Sina Weibo: @ Li huaming Himi)
Reproduced from the black meters GameDev block) original link: http://www.himigame.com/cocos2d-html5/1463.html

☞Click to subscribe☜The latest developments in this blog! Notify you of the latest blog in time!


I did not write a blog for a while. During this time, there were a lot of things happening, and I did some things I liked, I am mainly working on various editors based on the Cocoa framework of the Mac system. By the way, early this year also made his second book "iOS game programming from scratch-Cocos2d-x and cocos2d engine game development")

Nonsense, recently studied the Cocos2d-HTML5 related engine, in fact speaking of HTML5, 3, 4 years ago, Himi was in contact with the HTML5 Canvas at that time I was very impressed, but whether at that time or now for HTML5 most companies are still in the wait-and-see State, I am no exception, undoubtedly wait-and-see period is also constantly engine based HTML5, such as the current Cocos2d-HTML5, there will also be HTML5 Based on Untiy3D later. In general, HTML5 is a trend, just a matter of time.

So this article, briefly describes the Cocos2d-HTML5 to create a new project process and the relationship with cocos2d/x.

Step 1: first download the Cocos2d-html5 engine: http://cocos2d-x.googlecode.com/files/Cocos2d-html5-v2.1.5.zip

Currently, Himi is downloading the latest version 2.1.5.


Step 2: Decompress the engine package and the directory is as follows:

650) this. width = 650; "class =" alignnone size-full wp-image-1464 "alt =" QQ20130821-2 "src =" http://www.bkjia.com/uploads/allimg/131228/062Z333I-0.png "style =" max-width: pixel PX; border: 1px solid #999999; margin: 0px; padding: 4px; height: auto; "height =" 293 "width =" 202 "/>


Step 3: Take the HelloHTML5World project as an example. You can directly open index.html in the HelloHTML5World folder in a browser to run this sample project.

The following figure shows the effect of running to a browser:

650) this. width = 650; "class =" alignnone size-medium wp-image-1465 "alt =" QQ20130821-4 "src =" http://www.bkjia.com/uploads/allimg/131228/062Z330I-1.png "style =" max-width: pixel PX; border: 1px solid #999999; margin: 0px; padding: 4px; height: auto; "height =" 226 "width =" 300 "/>


The running effect is as above. This is actually an error. Don't worry. The reason is only the reason why resource preparation fails)

Regardless of the problem, let's take a look at the entire project structure: (The TextMate opened by Himi)

650) this. width = 650; "class =" alignnone size-medium wp-image-1468 "alt =" 1 "src =" http://www.bkjia.com/uploads/allimg/131228/062Z36315-2.jpg "style =" max-width: pixel PX; border: 1px solid #999999; margin: 0px; padding: 4px; height: auto; "height =" 214 "width =" 300 "/>


Brief description:

1. res resource storage directory

2. src js Script directory (our project source code directory)

3. build. xml: Compile the cocos2d engine into a js script file.

4. cocos2d. js: configuration file for cocos2d engine parameter settings

5. index.html: configuration file for the current view

6. main. js: main program entry


So many readers are wondering how to get started?

In fact, very simple, you can understand, cocos2d-html5 engine is just cocos2d engine framework directly mapped to the html5 api implementation process, we write cocos2d engine code through js language form, complete cocos2d engine form code to manage the entire HTML5 project. You can simply write the code in cocos2d/x format, but the language requires the js format.


How to create a new HTML5 project:

Step 1: copy the HelloHTML5World folder under the cocos2d-html5 Engine Directory directly, and the file name can be customized.

Step 2: copy the Cocos2d-html5-v2.1.5.min.js file under the lib folder under the engine directory to the project folder in your first step.

The role of the Cocos2d-html5-v2.1.5.min.js file: Will cocos2d engine in HTML5 api form ing js library for our project, if you do not copy this project to your project, you can not run.

I wonder why the HelloHTML5World project under the engine does not need it? In fact, this example project is used to map each engine class to js under the engine directory path. For example:

650) this. width = 650; "class =" alignnone size-medium wp-image-1469 "alt =" QQ20130821-6 "src =" http://www.bkjia.com/uploads/allimg/131228/062Z33637-3.png "style =" max-width: pixel PX; border: 1px solid #999999; margin: 0px; padding: 4px; height: auto; "height =" 160 "width =" 300 "/>


And why is there a min for this Cocos2d-html5-v2.1.5.min.js file? This is in fact the previous Cocos2d-html5-v2.1.5.jsb.js, a simple understanding is the js Code for a compression, the code in the table spaces are removed, save the file size of a form.

Step 3: directly use a browser to run index.html under the project.


Of course, the running effect at this time is the same as that of the HelloHTML5World project. The main reason is that the project cannot be started properly due to browser restrictions on resource loading.

This problem is actually a browser to prevent phishing, AJAX protection, and the cocos2d-html5 engine to request images is AJAX.

Therefore, we can solve this problem in two ways:

1. Install the web server and apache locally, and publish the project to the web server.

2. directly use Firefox for debugging. Firefox has no restrictions.

The following figure shows the running result of Firefox:

650) this. width = 650; "class =" alignnone size-medium wp-image-1471 "alt =" QQ20130821-9 "src =" http://www.bkjia.com/uploads/allimg/131228/062Z32H8-4.png "style =" max-width: pixel PX; border: 1px solid #999999; margin: 0px; padding: 4px; height: auto; "height =" 216 "width =" 300 "/>


OK, everything is normal, and the rest will be handed over to you.


This article is from the "Li huaming Himi" blog, please be sure to keep this source http://xiaominghimi.blog.51cto.com/2614927/1279847

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.