Saturday, January 17, 2015

[Tutorial] Cocos2d-x: Menu, from basic to advanced

Now, let's start. Create a new Project named Menu as follow, using cmd 

>cocos new menu -p -l cpp -d f:android/project

After new Project is created, you should run this command

>cocos compile -s f:android/project/menu -p win32

This is the first compile, purpose is linking to libraries in Engine. The first time to compile is so long. The next compile will be much faster because we only change some in Class and Resource.

Step 1) Copy code and run
You open Classes folder as following path E:/android/project/menu/Classes with 4 familiar files. But here we won't use class HelloWorldScene but replace by 2 other classes: MenuLayer and SceneManger.

You delete 2 files HelloWorldScene.cpp and HelloWorldScene.h, download source files Here and copy 4 files in zip file into Classes folder. And then you open file AppDelegate.cpp, in the second line #include you replace HelloWorldScene.h by  SceneManager.h, 
Delete the line auto scene = HelloWorld::createScene();
and director->runWithScene(scene); đi nhé. 
Add the following command SceneManager::goMenu(); into under the two above lines

Done, before compiling and running you open file Menu.vcxproj as following path E:/android/project/menu/proj.win32/ and find "HelloWorldScene.cpp" You will see 4 files here when compiled (HelloWorldScene.h, HelloWorldScene.cpp, AppDelegate.cpp, AppDelegate.h )

Because you deleted files HelloWorldScene.h and HelloWorldScene.cpp so here you delete too. And add 4 files SceneManager.h, SceneManager.cpp, MenuLayer.h , MenuLayer.cpp into Menu.vcxproj for compiler to process these 4 files when we compile again to run, as follow:

Posted By Dev Bananaer11:21 PM

Tuesday, January 13, 2015

[Tutorial] Ball - Basic Physics in cocos2d-x

Let's start

First, create a new project using cmd

>cocos new Ball -p -l cpp -d E:/android/project

Explain a bit, the above command will create a Project named Ball in folder E:/android/project

-p is the syntax of package. You can change a bit but must have 2 dots (.) like above. 
-l cpp: is the choice of C++
-d E:/android/project: is the folder that Project saved

Posted By Dev Bananaer11:39 PM

[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

>cocos new HelloWorld -p -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
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. <- 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
>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

Monday, January 12, 2015

[Tutorial] How to setup Cocos2d - x V3.0 FINAL on Window OS step-by-step, 100% Working

Filled under:

Setup this Engine is really difficult to many one, because of not simple as running only file setup.exe, then Next, Next, finish. It requires system configuration, and setup auxiliaries for running. And running it also works through an editor program (like Visual Studio). 

Posted By Dev Bananaer8:31 PM

Choose an Android item