How to create a "Hello World" C++ project with cocos2d-x2.2.2 or 3.0(Tutorial by YUYE)

Erro: your process of create project is too old
You should Create project like this way:
Step1:

You need download a Cocos2d-x engine

for latest Cocos2d-x version:

https://github.com/cocos2d/cocos2d-x

Or the stable version at the official site:

http://www.cocos2d-x.org/download

Choose by preference but note that going with the latest means you won’t be able to experience the latest features. My suggestion is to download git tools and clone to local to update.
Step2:

Going under the path with cmd terminal tool.

cd /Users/UserName/cocos2d-x-2.2.1/tools/project-creator

If you are using stable version 2.2.* cocos2d-x
you can create project by command:(python’s environment will be required)

python create_project.py -project MyGame -package com.MyCompany.AwesomeGame -language cpp

If you are using stable version 3.*

python create_project.py -n MyGame -k com.MyCompany.AwesomeGame -l cpp -p /Users/UserName/cocos2d-x-3.0beta/project 

Options:
~~h, —help show this help message and exit
~~n PROJECT_NAME, —name=PROJECT_NAME
Set a project name
~~k PACKAGE_NAME, —package=PACKAGE_NAME
Set a package name for project
~~l PROGRAMMING_NAME, —language=PROGRAMMING_NAME
Major programming language you want to use, should be
[cpp | lua | javascript]
-p PROJECT_PATH, —path=PROJECT_PATH
Set generate project path for project


FCD38039-7AC2-41DC-96B7-36281CF92CE0.png (18.2 KB)


D84CBA92-0161-4D4E-B34B-3941DDC6B73A.png (16.4 KB)

Hi, nice tutorial, thanks.
I advice you should place any tag in the topic. For example [Yuye Liu tutorials] as a prefix :slight_smile: It will make searching your tutorials easeier in future.
In my opinion you should also write about integration created cocos2dx project with specific IDE (Xcode, Eclipse, etc.).
Moreover I can’t see is it tutorial for Mac OSX or Linux.
Good luck! :slight_smile:

Thank you for your advise. I ’ll set the tag for my tutorial. like “(Tutorial by YUYE)”.

In my opinion. there is a easy way to create a game. I think its no reason to find another difficult solutions to do it .

My wish is using more time publish more basic tutorial for more cocos2d-x developer developing game quickly.

Tobias S wrote:

Hi, nice tutorial, thanks.
I advice you should place any tag in the topic. For example [Yuye Liu tutorials] as a prefix :slight_smile: It will make searching your tutorials easeier in future.
In my opinion you should also write about integration created cocos2dx project with specific IDE (Xcode, Eclipse, etc.).
Moreover I can’t see is it tutorial for Mac OSX or Linux.
Good luck! :slight_smile:

Great! Can’t wait for more tutorials :slight_smile:

@yuye liu
Creating a project was always easy.
Compile and start an Android project is more difficulty. So my wish:
Can you add a tut how to compile and start a cocos2dx 3.0 cpp on android from a windows deveolpe machine?

ok, I’ll make it soon. please check this topic today.

P. E. wrote:

@yuye liu
Creating a project was always easy.
Compile and start an Android project is more difficulty. So my wish:
Can you add a tut how to compile and start a cocos2dx 3.0 cpp on android from a windows deveolpe machine?

Hi Yuye,

I have problem with create_project.py, that by default its adding support of Box2d and chipmunk. So if i dont want to include these both lib in my project what should i do?
I already tried by removing these lines

LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static
LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static
$(call import-module,external/Box2D)
$(call import-module,external/chipmunk)

from jni/android.mk file. But doesnt help me, it still compiling and adding into my project .so file, which is not good if i am not using it.
Any help will be great.

thanks,

Hi,

But there isn’t create_project.py on cocos2d-x-3.0rc0.

Please help me to create a new c++ cross platform project on windows8.

@yagoub
here is the example and you need to download “ANT” at first

Example:

$ cd cocos2d-x
$ ./setup.py
$ source FILE_TO_SAVE_SYSTEM_VARIABLE
$ cocos new MyGame -p com.your_company.mygame -l cpp -d /home
$ cd /home/MyGame

Thanks :slight_smile: @yuye
I have imported the proj.android in ADT, it was fine , but i can’t run this project on my device.
This is my LogCat

03-28 07:12:28.708: I/dalvikvm(6642): Turning on JNI app bug workarounds for target SDK version 9…
03-28 07:12:28.770: D/AndroidRuntime(6642): Shutting down VM
03-28 07:12:28.770: W/dalvikvm(6642): threadid=1: thread exiting with uncaught exception (group=0x41e272a0)
03-28 07:12:28.770: E/AndroidRuntime(6642): FATAL EXCEPTION: main
03-28 07:12:28.770: E/AndroidRuntime(6642): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.your_company.hellocpp/org.cocos2dx.cpp.Cocos2dxActivity}: java.lang.IllegalArgumentException: Unable to find native library: cocos2dcpp
03-28 07:12:28.770: E/AndroidRuntime(6642): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
03-28 07:12:28.770: E/AndroidRuntime(6642): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
03-28 07:12:28.770: E/AndroidRuntime(6642): at android.app.ActivityThread.access$600(ActivityThread.java:140)
03-28 07:12:28.770: E/AndroidRuntime(6642): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
03-28 07:12:28.770: E/AndroidRuntime(6642): at android.os.Handler.dispatchMessage(Handler.java:99)
03-28 07:12:28.770: E/AndroidRuntime(6642): at android.os.Looper.loop(Looper.java:137)
03-28 07:12:28.770: E/AndroidRuntime(6642): at android.app.ActivityThread.main(ActivityThread.java:4895)
03-28 07:12:28.770: E/AndroidRuntime(6642): at java.lang.reflect.Method.invokeNative(Native Method)
03-28 07:12:28.770: E/AndroidRuntime(6642): at java.lang.reflect.Method.invoke(Method.java:511)
03-28 07:12:28.770: E/AndroidRuntime(6642): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
03-28 07:12:28.770: E/AndroidRuntime(6642): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
03-28 07:12:28.770: E/AndroidRuntime(6642): at dalvik.system.NativeStart.main(Native Method)
03-28 07:12:28.770: E/AndroidRuntime(6642): Caused by: java.lang.IllegalArgumentException: Unable to find native library: cocos2dcpp
03-28 07:12:28.770: E/AndroidRuntime(6642): at android.app.NativeActivity.onCreate(NativeActivity.java:187)
03-28 07:12:28.770: E/AndroidRuntime(6642): at org.cocos2dx.cpp.Cocos2dxActivity.onCreate(Cocos2dxActivity.java:14)
03-28 07:12:28.770: E/AndroidRuntime(6642): at android.app.Activity.performCreate(Activity.java:5163)
03-28 07:12:28.770: E/AndroidRuntime(6642): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
03-28 07:12:28.770: E/AndroidRuntime(6642): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061)
03-28 07:12:28.770: E/AndroidRuntime(6642): … 11 more

@yagoub Did u run HelloWorld

Now, i have this problem

C:\home\MyGame\proj.android\proj.android>python build_native.py
The Selected NDK toolchain version was 4.8 !
Android NDK: WARNING: Ignoring unknown import directory: C:\home\MyGame\proj.and
roid\proj.android…/cocos2d
Android NDK: WARNING: Ignoring unknown import directory: C:\home\MyGame\proj.and
roid\proj.android…/cocos2d/external
Android NDK: WARNING: Ignoring unknown import directory: C:\home\MyGame\proj.and
roid\proj.android…/cocos2d/cocos
Android NDK: jni/Android.mk: Cannot find module with tag ‘2d’ in import path

Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?

Android NDK: The following directories were searched:
Android NDK:
make.exe: Entering directory C:/home/MyGame/proj.android/proj.android' jni/Android.mk:22: *** Android NDK: Aborting. . Stop. make.exe: Leaving directoryC:/home/MyGame/proj.android/proj.android’
Traceback (most recent call last):
File “build_native.py”, line 166, in
build(opts.ndk_build_param,opts.android_platform,opts.build_mode)
File “build_native.py”, line 153, in build
do_build(cocos_root, ndk_root, app_android_root,ndk_build_param,sdk_root,and
roid_platform,build_mode)
File “build_native.py”, line 89, in do_build
raise Exception(“Build dynamic library for project [ " + app_android_root +
" ] fails!”)
Exception: Build dynamic library for project [ C:\home\MyGame\proj.android\proj.
android ] fails!

My environment variables are:

ANDROID_SDK_ROOT C:\Android\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk

ANT_ROOT C:\Android\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\apache-ant-1.9.3-bin\apache-ant-1.9.3\bin

NDK_ROOT C:\Android\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\android-ndk-r9d-windows-x86_64\android-ndk-r9d