Cocos2dx
lastmod 2021-05-28created 2014-12-2126 edits
Project
- Cocos2d-x: written in C++ and OpenGL ES 1.1/2.0, run on iOS, Android, BlackBerry, Bada, Marmalade, Windows, Linux and more.
- Cocos2d-html5: Written in javascript, based on HTML5 technology. This branch focus on desktop browsers and hybrid app of mobile.
- Cocos2d-XNA: written in C#, based upon Microsoft XNA 4, compatible with Windows Phone 7, Windows Phone 8, Android, iOS, PSM, WinRT, Win Desktop, and Linux.
Category
Cocos2d-x Basics
- Cocos2dx:Android: Cocos2dx for android
- Cocos2dx:Coordinate: Cocos2dx coordinate system
- Cocos2dx:CCNode
- Cocos2dx:CCDirector
- Cocos2dx:CCScene
- Cocos2dx:CCLayer
- Cocos2dx:CCSprite
- Cocos2dx:CCAction
Menu
- Cocos2dx:CCMenu
- Cocos2dx:CCMenuItem
- Cocos2dx:CCMenuItemLabel
- Cocos2dx:CCMenuItemSprite
- Cocos2dx:CCMenuItemImage
- Cocos2dx:CCMenuItemToggle
Action
If the name ends in ~By, the action changes the current value by the specified amount; if it ends in ~To, the action changes it to the specified value.
- Position
- CCMoveBy, CCMoveTo
- CCJumpBy, CCJumpTo
- CCBezierBy, CCBezierTo
- CCPlace
- CCScaleBy, CCScaleTo
- CCRotationBy, CCRotationTo
- CCShow
- CCHide
- CCBlink
- CCToggleVisibility
- CCFadeIn
- CCFadeOut
- CCFadeTo
- CCTintBy
- CCTintTo
- CCSequence
- CCRepeat, CCRepeatForever
Transition
- Cocos2dx:CCFadeTransition
- Cocos2dx:CCFlipAngularTransition
- Cocos2dx:CCShrinkGrowTransition
- Cocos2dx:CCMoveInBTransition
- Cocos2dx:CCMoveInTTransition
- Cocos2dx:CCMoveInLTransition
- Cocos2dx:CCMoveInRTransition
- Cocos2dx:CCFadeTRTransition
- Cocos2dx:CCFadeUpTransition
- Cocos2dx:CCFlipXTransition
- Cocos2dx:CCFlipYTransition
- Cocos2dx:CCPageTurnTransition
- Cocos2dx:CCCrossFadeTransition
Animation
Schedule
Data storage
User input
Gravity & Accelerometer
How to build
## Clone the repo from GitHub.
$ git clone https://github.com/cocos2d/cocos2d-x.git
## After cloning the repo, please execute download-deps.py to download and install dependencies.
$ cd cocos2d-x
$ python download-deps.py
## After running download-deps.py.
$ git submodule update --init
How to Start a New Cocos2d-x Game
After downloading the library, you need to set the environment variables below. (Or run setup.py)
-
COCOS_X_ROOT: Directory where cocos2dx is installed. -
COCOS_CONSOLE_ROOT: cocos2dx console utility directory:$COCOS_X_ROOT/tools/cocos2d-console -
COCOS_TEMPLATES_ROOT: cocos2dx template directory:$COCOS_X_ROOT/templates -
NDK_ROOT: ROOT directory where the Android NDK is installed. -
ANDROID_SDK_ROOT: ROOT directory where the Android SDK is installed. -
ANT_ROOT: ROOT directory where Apache Ant is installed.
Then add $COCOS_CONSOLE_ROOT/bin to PATH so you can use the cocos (cocos.bat on windows) script.
To create a project, enter the following.
-
MyGame: name of your project -
-p com.MyCompany.MyGame: package name for android -
-l cpp: programming language used for the project, valid value is cppand lua -
-d ~/MyCompany: directory to hold your project
Quick start
$ cd cocos2d-x
$ ./setup.py
$ source FILE_TO_SAVE_SYSTEM_VARIABLE
$ cocos new MyGame -p com.your_company.mygame -l cpp -d NEW_PROJECTS_DIR
$ cd NEW_PROJECTS_DIR/MyGame
How to run cpp-tests
## Install Dependencies
$ cd $cocos2dx_root/build
$ ./install-deps-linux.sh
## Generate Makefile
$ mkdir linux-build
$ cd linux-build
$ cmake ../..
## Compile
$ make
## Run
$ cd bin/cpp-tests/
$ ./cpp-tests
Detect the Collisions
Use CCRect.intersectsRect() to check for collisions.
CCRect projectileRect = CCRectMake(posx, posy, width, height);
CCRect targetRect = CCRectMake(posx, posy, width, height);
if (projectileRect.intersectsRect(targetRect)) {
// ...
}
Troubleshooting
Notes on problems and how to solve them.
Android eclipse project: C/C++ Indexer error
- http://dissonanz.tistory.com/38
- http://stackoverflow.com/questions/24882026/eclipse-project-disappearance-and-an-internal-error-occurred-during-launching
When building a cocos2d-x 3.2 Android Eclipse project, the following error occurs.
This problem occurs because the <cconfiguration> entry in the .cproject file is duplicated.
- Open
.cprojectin an editor. - Keep the first <cconfiguration> entry and remove all the others.
However, I'm not sure whether this is really a safe method.
Local Download
- cocos2d-x 3.10
- Cocos2d-x-cocos2d-x-3.10.tar.gz (Github source code only)
See also
Favorite site
How to install
Developers Manual
- cocos2d-x wiki Developers Manual
- How to Start a New Cocos2d-x Game
- Getting Started Installation and Testing
Guide
- Cocos 2D-x compiling with CLion/CMake under Windows
- cocos2dx installation and run errors ( errors from installing on window7.)
- cocos2d-x android setup @windows
- cocos2d-x coordinate system: Position and Anchor
- Pausing a cocos2d-x game and showing a popup window (pause, resume)
- A review of key Cocos2D classes : CCScene, CCDirector, CCLayer, CCScene, CCNode
- Cocos2d Basic Concepts