Architecture and Directory Structure
1. Cocos2d-x
1.1 Architecture
1.2 Directory Structure¶This document is describing the folder structure of cocos2d-x v3.0-alpha1 and later.
After you download cocos2d-x repo from github, or unzip a stable release zip ball, you will see the directory structure like this:
Directory | Explain |
---|---|
build | This folder includes top level xcode projects, visual studio solutions and makefiles |
cocos | This is the major directory for cocos2d-x framework. |
docs | You can download doxygen, use it to open doxygen.config file in this this folder, then generate offline API docs by yourself |
extensions | This folder is almost deprecated after v3.0. Please use cocos/gui instead of extensions/GUI, use cocos/physics instead of extension/physics-nodes. Assets-manager can work but will be refactor sooner |
external | Here are all 3rd libraries which is dependencied by cocos2d-x |
licenses | Cocos2d depends on many other open source projects. All of their licenses are here. We've avoid all GPL/LGPL libraires, so cocos2d-x and its dependencies are commercial friendly. |
samples | IMPORTANT. This is where you should start from. Cpp/HelloCpp can be your first lesson, and you can find the usages of all classes in TestCpp. Looking for lua and js samples? They’re also here. |
template | Here're templates for creating cocos2d-x new project in different IDEs and various platforms. |
tools | Lots of different command line tools, such as createing new projects, binding c++ to lua to javasript, compile javascript into bytecode, etc. We're refactoring this into cocos-console. |
2. Cocos2d-html5
2.1 Architecture
2.2 Directory Structure
Directory | Explain |
---|---|
CocosDenshion | Audio support. Note that you need at least two audio formats to support all browsers |
cocos2d | Main directory, contains everything and maintains API the same as Cocos2d-x and Cocos2d-iPhone. The platform compatibility is well designed, enjoy it |
box2d | Box2dweb Physics engine v2.1a |
chipmunk | Chipmunk Physic engine with no version number, ;) |
Demo | There are couples demos which you may get started from them |
extensions | If you looking for more GUI controls, EditBox, CocosBuilder support, CocoStudio support, or any third party libs, that’s where it is |
HelloHTML5Wrold | An advance Hello World for you to get started |
lib | It contains a min version engine when you run /cocos2d/build.xml with ant tool to package all engine flies to a single file |
licenses | Cocos2d depends on many other open source projects. All of their licenses are here |
samples | You can find all classes usage in Tests. It also includes sample games. All the tests and games can be run in JSB.IMPORTANT. This is where you should start from |
template | templates for creating a new Cocos2d-html5 project |
tools | JSDoc and Closure Compiler |
index.html | Index of Cocos2d-html5 |
AUTHORS | List of all contributors |
CHANGELOG | Well, it lists changes that above guys have done |
3. Javascript Binding
Crossing platform is good, but not good enough. Programming in C++ is super slow, in the other hand, C++ code cannot run on web browsers. That’s why we add javascript binding. We can pack javascript code into:
- native app on cocos2d-x + SpiderMonkey, which can parse javascript code into C.
- web app on cocos2d-html5
We have a same API set on cocos2d-x and cocos2d-html5. Therefore, we can create 100% javascript game natively in cocos2d-x. When you want to run it on browsers, want you need is only switch engine to cocos2d-html5, without modifying your source code.
The benefits are:
- Much faster coding speed than c++
- Don’t need to deal with wild pointers / reference count / memory leak
- Crossing both native and web
- Online updating