Showing posts with label HelloWorld cocos2d-x. Show all posts
Showing posts with label HelloWorld cocos2d-x. Show all posts

Tuesday, January 13, 2015

[Tutorial] Hello cocos2d-x. The first code - Hello World!

Filled under:

A - Create and run Project

First, create a new project named HelloWorld using cmd

Run/cmd
>cocos new HelloWorld -p com.vn.HelloWorld -l cpp - d E:/android/myproject

Wait for 5 minutes to create new Project...

It's done. Go to new project in the following path
E:/android/myproject/helloworld
You can see the folder structure as follow:

Classes <- The most important, contains cpp or lua upon to your choice of language in above command.
cocos2d <- library of engine Cocos2d-x.
proj.android <- for building apk for Android mobile.
proj.ios_mac  <- for building apps for Iphone and Mac OS ( only run on Apple computers, or computer that installed Mac OS.
proj.linux <- for building apps on Linux machine.
proj.win32 <- for building apps on Windows 7, 8 OS
proj.wp8-xaml <- for building apps running on Windows Phone 8
Resources <- contains images, fonts, Maps, physics definition, etc.
.cocos-project.json <- for building project with lua or cpp.
CMakeLists.txt <- List libraries for building project.

Continue, we build and run on Windows. Using following command

>cocos run -s E:/android/myproject/helloworld -p win32

(enter cocos run -h for help)

>cocos compile -s E:/android/myproject/helloworld -p android --ap 16
--ap 16 is for android 4.1.2 or higher

Install on emulator
>adb install E:/android/myproject/helloworld/bin/debug/android/helloworld-debug-unligned.apk
or
>cocos run -s E:/android/myproject/helloworld -p android --ap 16

If error, remove --ap 16, as follow:
>cocos run -s E:/android/myproject/helloworld -p android

If not error and appear like this, it means you succeed. 


Posted By Dev Bananaer6:49 PM

Choose an Android item