Posted on

1. Prerequisite Cocos2d-X

Welcome Guys to First lesson of Cocos2d-X v 2.2.2 Tutorial Series

Prerequisite
Summary: 
In this Lesson i am going to teach you (Ok i am not a teacher so i am going to show you instead of  teach you “teach  -> Show)
Setting up Cocos2d-x for all major Platform (Just leaving IOS  because of no MAC & IOS Device for testing & some others which are simple & easy)
& Running Sample app TestCPP
Detail:
Download Cocos2d-X V 2.2.2 from here http://cdn.cocos2d-x.org/cocos2d-x-2.2.2.zip
After downloading it save  to directory without Spaces in path for example:
C:Downloads Filescocos2d-x-2.2.2cocos2d-x-2.2 (Wrong)
C:Downloadscocos2d-x-2.2.2cocos2d-x-2.2          (Right)
Extract it using any software (I don’t care what you use..😀 )
1. Let’s start with Windows
using Visual Studio (If you don’t have a copy you can get it from Dreamspark by verifying your Student Status) .Installing Visual Studio is easy just do couple of clicks Next Next and Install type
Open this solution file

in Visual Studio 2012 as it’s for VS 2012 (If you want to open in any Greater version then please google it)
Right Click on TestCPP in solution explorer
like this
and select set as Startup Project
Then Click on the Play icon (which you saw in most Music Player in this Software it’s not called Play Icon)
If any Pop up askes to compile other Projects click yes
Click on it wait for it to complete the process (The time for compiling is much more then expected and also depends upon your Computer )
Now when you have completed it it will open a Window for you to show TestCPP app it’s a demo application to check Cocos2d-X features 
Click on every List item and check it’s feature what you can achieve with Cocos2d-X the power of cocos2d-x is not limited to these features you can achieve anything 
2. Let’s come to Android Version
1. Go to the Android Developer Site download ADT Bundle (http://developer.android.com/sdk/index.html)
&
2. Download the NDK (Native Development Kit)
Q: What is ADT Budle ?
A:  ADT Bundle includes Eclipse with SDK Manger and other tools to get you started in development of Android APPS & GAMES using SDK (Software Development Kit)
Q: What is NDK ?
A: NDK stands for Native Development Kit . It let’s you run C  / C++ Code in Android app . As you know Cocos2d-X is Cross platform & it’s run with C++ Language . So we need Android NDK
3. Download CYGWIN

Install Packages from any Single mirror site (Please check Make Packages are included in it)
now you are ready to make TestCPP for your andorid Device/Emulator/Bluestacks
Open ADT Bundle Folder – > Eclipse -> eclipse.exe
Import the TestCPP
File -> Import -> Existing Project into workspace -> Select Root directory -> Browse
C:Downloadscocos2d-x-2.2.2cocos2d-x-2.2samplesCppTestCppproj.android
Press Ok

Now Setting Variables
* Windows->Preferences->General->Workspace->Linked Resources
Click on New ->
In Name field:- COCOS2DX
In Location field:- The Root Directory in my PC it’s  
C:Downloadscocos2d-x-2.2.2cocos2d-x-2.2

Now we have to set NDK_ROOT Environment Variable
Windows -> Prefrences -> C/C++ -> Build -> Environment ->
Click on Add button (Right Side)
In Name field: NDK_ROOT
In Values field: The Root Directory of NDK (C:Downloadsandroid-ndk-r9-windows-x86_64android-ndk-r9) 

Also add these two Variables 
In Name field: CYGWIN
In Values field: nodosfilewarning
In Name field: SHELLOPTS
In Values field: igncr
Last thing what we have to do is 
Importing libcocos2dx Lib project
Same process for importing
File -> Import -> Existing Project into workspace -> Select Root directory -> Browse
Cocos2d-X ROOT/cocos2dx/platform/android/java (My PC – > C:Downloadscocos2d-x-2.2.2cocos2d-x-2.2cocos2dxplatformandroidjava)
Finish -> Ok
now if everything is gone as per tutorial you will not face any problem and it will get compiled Successfully
On TestCPP -> Right Click -> Run As -> Android Application
now make some coffee  because it will take much time to compile all Files after Completion of this Process open it in emulator or BlueStacks or any Device 
i will recommend BlueStacks instead of Emulator (Sometimes it will not able to run just Black screen ,It’s slow as comparison to Bluestacks )
NOTE: if you got any error Clean the Project Project-> Clean then Build it again Or
Post in Comments 🙂
3. Marmalade
Make sure you have Marmalade Installed on your System Open proj.marmalade folder in 
C:Downloadscocos2d-x-2.2.2cocos2d-x-2.2samplesCppTestCppproj.marmalade

Double click on TestCPP.mkb file it will let you open in the Visual Studio or Right click and open it with Marmalade HUB
4.BB 10

Install Blackberry Native SDK (https://developer.blackberry.com/native/downloads/)
For testing purpose download Simulator also (I would recommend Device DAC,DAB or any other)

Import TestCPP from proj.blackberry directory

Open Blackberry Native SDK -> File -> Import -> Existing Projects into WorkSpace -> Browse -> Finish -> Ok

Now some projects are also Required to build TestCPP or any other Sample / Your Project Successfully

extensions -> C:Downloadscocos2d-x-2.2.2cocos2d-x-2.2extensionsproj.blackberry

CocosDenshion  -> C:Downloadscocos2d-x-2.2.2cocos2d-x-2.2CocosDenshionproj.blackberry

Cocos2dx -> C:Downloadscocos2d-x-2.2.2cocos2d-x-2.2cocos2dxproj.blackberry

Box2D -> C:Downloadscocos2d-x-2.2.2cocos2d-x-2.2externalBox2Dproj.blackberry

Chipmunk -> C:Downloadscocos2d-x-2.2.2cocos2d-x-2.2externalchipmunkproj.blackberry

so import these Projects one by one or select Cocos2d-x Root directory and select it in List view of Check boxes

Now if you want to make for Simulator go to all of these projects Including TestCPP
Select Project – > right click -> Properties -> C/C++ Build -> Manage Configuration Select Simulator (Do same for Device if you want to make it for Device)

Select Configuration from drop down menu Simulator (Active)
do all these for all Projects 😀 because the build Library will be in that folder

For example you have choose Device-Release in Cocos2dx Project or CocosDenshion and your TestCPP is in Simulator configuration it will look for cocos2dx lib file in Simulator folder but actually the file is in Device-Release

so it will show you error be care full and choose appropriate  configuration
to run on simulator Add a new target if no simulator is found & Right click on Project Run As Blackberry C/C++ Application

____________________________________________________________________________

For WP8 i would recommend Cocos2d-XNA instead of Cocos2d-x as it will let you able to make it for WP7 & WP8

So i am not covering it in this Tutorial may be in Future

Some Advice :

Build your Project on Windows in Visual Studio write code and test it on Machine instead of slow emulators/Simulators/ and checking again and again on Device when you find it’s working fine and completed then go in Eclipse import the project as the Classes folder will be same on all Platform run it on Device or Bluestacks For android

do same thing for Blackberry or any other Platform it will save you lot of headache and Time..

In next tutorial I will show you how to create your own Project & write Hello World!

Check Index of Cocos2d-X Tutorial Series