Cocos2s-x架构

Architecture and Directory Structure

1. Cocos2d-x

1.1 Architecture

1.2 Directory Structure

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     
CocosDenshion Audio support. Note that BGM and short effects are using different OS API on android
cocos2dx Major directory, involves everything except cash. Sorry I'm wrong, some 2dx games earns +2 million dollars per month. So it should involves money. The platform adapter is well designed, enjoy it
document You can download doxygen, use it to open doxygen.config file in this document folder, then generate offline API docs by yourself
extensions If you looking for more GUI controls, network access, CocosBuilder support, and even 2.5D feature, that's it. using namespace cocos2d::extension
external physics libraries, box2d and chipmunk
licenses cocos2d depends on many other open source projects. All of their licenses are here
samples IMPORTANT. This is where you should start from. Cpp/HelloCpp is your first lesson, and you can find all classes usage in TestCpp. Looking for lua and js samples? They're also here
scripting Yeah I know, you hate c++, it's too complicated. No problem, Lua and Javascript is ready. Scripting folder includes lua official engine, and SpiderMonkey which we pick up from FireFox
template templates for creating cocos2d-x new project in different IDEs and various platforms. I don't know if there're such many IDEs and OS platforms on Mars
tools scripts for binding c++ to lua, c++ to javascript
CHANGELOG well, I don't know what does changelog mean. Can anyone who tell me please?
cocos2d-win32.vc2010.sln Open with Visual Studio 2010. Note that VS2008 is not supported anymore since cocos2d-x v2.0
cocos2d-win32.vc2012.sln Open with Visual Studio 2012
create-android-project.bat Run it on windows. Please refer to How to create android project with script for usage
create-android-project.sh Run it on linux and osx. Please refer to How to create android project with script for usage
install-templates-msvc.bat After this installation, you can create empty cocos2d-x project in Visual Studios
install-templates-xcode.sh After this installation, you can create empty cocos2d-x project in Xcode

2. Cocos2d-html5

2.1 Architecture

2.2 Directory Structure

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, 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. All the tests 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:

  1. native app on cocos2d-x + SpiderMonkey, which can parse javascript code into C.
  2. web app on cocos2d-html5

We have a same API set on cocos2d-iphone, cocos2d-x and cocos2d-html5. Therefore, we can create 100% javascript game natively in cocos2d-x/cocos2d-iphone. 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:

  1. Much faster coding speed than c++
  2. Don't need to deal with wild pointers / reference count / memory leak
  3. Crossing both native and web

 

Last updated by Zhe Wang at 更新于 6 个月 之前.

猜你喜欢

转载自hougechuanqi.iteye.com/blog/1895079