Skip to content
Search

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: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
  • Scale
    • CCScaleBy, CCScaleTo
  • Rotation
    • CCRotationBy, CCRotationTo
  • Visibility (Visible)
    • CCShow
    • CCHide
    • CCBlink
    • CCToggleVisibility
  • Opacity
    • CCFadeIn
    • CCFadeOut
    • CCFadeTo
  • Color
    • CCTintBy
    • CCTintTo
  • Composition
    • CCSequence
  • Repeat
    • 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.

$ cocos new MyGame -p com.MyCompany.MyGame -l cpp -d ~/MyCompany
  • 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

When building a cocos2d-x 3.2 Android Eclipse project, the following error occurs.

An internal error occurred during: "C/C++ Indexer"
 java.lang.NullPointerException

This problem occurs because the <cconfiguration> entry in the .cproject file is duplicated.

  1. Open .cproject in an editor.
  2. 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

Guide

Tutorial

References


  1. Cocos2dx-3.3-ProgrammersGuide.pdf ↩

  2. Cocos2dx-3.9-ProgrammersGuide.pdf ↩

  3. Build_a_Collaborative_Drawing_App.zip ↩

author Zer0 sitemap