Skip to content

Cocos2d-x is a suite of open-source, cross-platform, game-development tools used by millions of developers all over the world.

Notifications You must be signed in to change notification settings

WuJiayiSH/cocos2d-x

 
 

Repository files navigation

Examples: https://wujiayish.github.io/cocos2d-x-examples/

In order to build cocos2d-x project into HTML5/wasm, make sure you have installed emsdk(3.1.10 is recommended)

# Get the emsdk repo
git clone https://github.com/emscripten-core/emsdk.git

# Enter that directory
cd emsdk

# Download and install the SDK tools, 3.1.10 is recommended.
./emsdk install 3.1.10

# Make the SDK "active" for the current user. (writes .emscripten file)
./emsdk activate 3.1.10

# Activate PATH and other environment variables in the current terminal
source ./emsdk_env.sh

On Linux and Mac:

# Install cocos2d-x with python2.7
git clone https://github.com/WuJiayiSH/cocos2d-x.git
cd cocos2d-x
git submodule update --init
# export EMSDK_ROOT as environment variable
./setup.py
source FILE_TO_SAVE_SYSTEM_VARIABLE
cd ..

# Compile and check build from emscripten-build/bin/MyGame
cocos new MyGame -p com.your_company.mygame -l lua
cd MyGame
cocos compile -p emscripten -m release

On Window 10 or above, install cmake and ninja 1.12.0 or above(https://github.com/ninja-build/ninja) and make sure they can be found from command line:

# Install cocos2d-x with python2.7
git clone https://github.com/WuJiayiSH/cocos2d-x.git
cd cocos2d-x
git submodule update --init
# export EMSDK_ROOT as environment variable
python setup.py
cd ..

# Compile and check build from emscripten-build/bin/MyGame
cocos new MyGame -p com.your_company.mygame -l lua
cd MyGame
cocos compile -p emscripten -m release

Thread support is enabled by default, you can use Chrome argument --enable-features=SharedArrayBuffer for test or serve the build with addtional headers for it to work, see https://developer.chrome.com/blog/enabling-shared-array-buffer/

Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Opener-Policy: same-origin

You can disable thread support in cpp or lua projects by removing "-s USE_PTHREADS" from CmakeLists.txt, in the case most thread-related functions like addImageAsync will not work. But you may have to enable it in js project because SpiderMonkey uses threads.

Thread support uses Javascript SharedArrayBuffer, check https://caniuse.com/sharedarraybuffer for browser compatibility.

TODO:

  1. Files under WritablePath will be lost between game sessions

Backlogs:

  1. Implement UIEditBox.cpp
  2. Implement WebSocket.cpp
  3. Investigate setAccelerometerEnabled, setAccelerometerInterval, getTextureDataForText in CCDevice
  4. Compile tiff, webp
  5. Investigate getDuration, getCurrentTime, setCurrentTime in AudioEngine
  6. Response header in HttpResponse is missing

cocos2d-x

Win32 Others
Build status Build Status

cocos2d-x is a multi-platform framework for building 2d games, interactive books, demos and other graphical applications. It is based on cocos2d-iphone, but instead of using Objective-C, it uses C++. It works on iOS, Android, OS X, Windows, Linux and Web platforms.

Cocos2d-x Framework Architecture:

cocos2d-x is:

  • Fast
  • Free
  • Easy to use
  • Community supported

Git user attention

  1. Clone the repo from GitHub.

      $ git clone https://github.com/cocos2d/cocos2d-x.git
    
  2. After cloning the repo.

      $ cd cocos2d-x
      cocos2d-x $ git submodule update --init
    

Download stable versions

How to start a new game

  1. Download the code from cocos2d download site or clone this repo (instructions above)
  2. Run setup.py
  3. Run the cocos script

Example:

$ 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

You can also create a JS project or Lua project with -l js or -l lua.

Build and run a new project for Android

Cocos2d-x supports Android Studio. Simple open the proj.android directory from within the Android Studio environment. More information can be found in our documentation.

Build and run a new project for iOS

$ cocos run -p ios

Build and run a new project for OSX

$ cocos run -p mac

Build and run a new project for Linux

If you never run cocos2d-x on Linux, you need to install all dependencies by the script in cocos2d/build/install-deps-linux.sh

$ cd cocos2d-x/build
$ ./install-deps-linux.sh

Then

$ cd NEW_PROJECTS_DIR/MyGame
$ cocos run -p linux

Run

$ bin/MyGame

Build and run new project for win32

$ cocos run -p win32

Build and run new project for web

Only JS project can be published to web platforms, so you will need to create a JS project first:

$ cocos new -l js WebGame

Then you can run your game in a web browser:

$ cocos run -p web

Or you can publish your game to publish/html5/ folder:

$ cocos run -p web -m release [--advanced]

Using CMake

Cocos2d-x supports CMake, a cross-platform build system. Example usage:

$ cd cocos2d-x
$ mkdir cmake-build && cd cmake-build
$ cmake ..

Documentations and samples

Main features

  • Scene management (workflow)
  • Transitions between scenes
  • Sprites and Sprite Sheets
  • Effects: Lens, Ripple, Waves, Liquid, etc.
  • Actions (behaviours):
    • Transformation Actions: Move, Rotate, Scale, Fade, Tint, etc.
    • Composable actions: Sequence, Spawn, Repeat, Reverse
    • Ease Actions: Exp, Sin, Cubic, Elastic, etc.
    • Misc actions: CallFunc, OrbitCamera, Follow, Tween
  • Basic menus and buttons
  • Integrated with physics engines: Box2d and Chipmunk
  • Particle system
  • Skeleton Animations: Spine and Armature support
  • Fonts:
    • Fast font rendering using Fixed and Variable width fonts
    • Support for .ttf fonts
  • Tile Map support: Orthogonal, Isometric and Hexagonal
  • Parallax scrolling
  • Motion Streak
  • Render To Texture
  • Touch/Accelerometer on mobile devices
  • Touch/Mouse/Keyboard on desktop
  • Sound Engine support (CocosDenshion library) based on OpenAL
  • Integrated Slow motion/Fast forward
  • Fast and compressed textures: PVR compressed and uncompressed textures, ETC1 compressed textures, and more
  • Resolution Independent
  • Language: C++, with Lua and JavaScript bindings
  • Open Source Commercial Friendly(MIT): Compatible with open and closed source projects
  • OpenGL ES 2.0 (mobile) / OpenGL 2.1 (desktop) based

Build Requirements

  • Mac OS X 10.7+, Xcode 8+
  • or Ubuntu 14.04+, CMake 3.1+
  • or Windows 7+, VS 2015
  • Python 2.7.5+ (NOT Python 3)
  • NDK r16+ is required to build Android games
  • Android Studio 3.0.0+ to build Android games(tested with 3.0.0)
  • JRE or JDK 1.6+ is required for web publishing

Runtime Requirements

  • iOS 8.0+ for iPhone / iPad games
  • Android 3.0.0+ for Android
  • OS X v10.9+ for Mac games
  • Windows 7+ for Win games
  • Modern browsers and IE 9+ for web games

Running Tests

Select the test you want from Xcode Scheme chooser.

  • Cocos Console
// Enter cpp test folder
cd tests/cpp-tests
// Or enter js test folder
cd tests/js-tests
// Or enter lua test folder
cd tests/lua-tests

// Compile or run test case
cocos compile -p ios|mac|android|win32|win8_1|metro|web -m debug|release
cocos run -p ios|mac|android|win32|win8_1|metro|web -m debug|release
  • For OS X / iOS
$ cd cocos2d-x/build
$ open cocos2d_tests.xcodeproj
  • For Linux
$ cd cocos2d-x/build
$ ./install-deps-linux.sh
$ mkdir linux-build
$ cd linux-build
$ cmake ../..

Run Samples

$ bin/Debug/cpp-empty-test/cpp-empty-test
or
$ bin/Debug/lua-empty-test/lua-empty-test

You may meet building errors when building libGLFW.so. It is because libGL.so directs to an error target, you should make it to direct to a correct one. install-deps-linux.sh only has to be run once.

  • For Windows

Open the cocos2d-x/build/cocos2d-win32.sln

  • For Android
$ cd cocos2d-x/build
$ python ./android-build.py cpp-empty-test -p 14
$ adb install ../tests/cpp-empty-test/proj.android/bin/CppEmptyTest-debug.apk

Then click item on Android device to run tests. Available value of -p is the API level, cocos2d-x supports from level 14.

Or you can import the project located at tests/cpp-empty-test/proj.android using Android Studio 3.0.0+.

Learning Resources

Spreading the word!

You can help us spread the word about cocos2d-x! We would surely appreciate it!

  • Talk about us on Facebook! Our Facebook Page
  • Tweet, Tweet! Our Twitter
  • Read our Blog and promote it on your social media.

Where to get help

Contributing to the Project

Cocos2d-x is licensed under the MIT License. We welcome participation!

Did you find a bug? Do you have feature request? Do you want to merge a feature?

Contact us

About

Cocos2d-x is a suite of open-source, cross-platform, game-development tools used by millions of developers all over the world.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 76.7%
  • JavaScript 7.8%
  • Lua 7.0%
  • C 3.3%
  • Objective-C++ 1.3%
  • Objective-C 1.1%
  • Other 2.8%