How to port a simple project to win32,iPhone and Android (tutroial)

I finished the installation and set up for the cocos2d-x(iphone-android) under Mac OS yesterday,
here’s the article:

so I tried to port a very simple cocos2d-x win32 project I wrote several month ago to iPhone, android platform and win32 of course. The origin demo was here;

Here goes the whole process:

1.Create a new project(Xcode) named SimplePortDemo under Mac OS using cocos2d-x-iPhone and make a little bit change of the origin code
2.Create a new project named SimplePortDemo under Mac OS using cocos2d-x-android and then merge it into the iPhone project
3.Create a new project(VS2010) named SimplePortDemo under WinXP using cocos2d-x-win32

Here is the process in detail:

1.Create a project for iPhone and android under Mac OS

1.1 Create a new project named SimplePortDemo in Xcode

1.2 Create a new project named SimplePortDemo using the shell script in cocos2d-x-android

1.3 Copy the Android folder under SimplePortDemo to the following position:

1.4 Edit the config file (according to yesterday’s article)

1.5 Rename the “AppDelegate” file (a bug)

1.6 Complie && Run in Xcode and Success!

1.7 Input the project in to Eclipse

1.8 Complie && Run in Xcode and Success!

  1. Port the origin project to iPhone

2.1 Copy the HelloWorldScene, MenuScene file into Xcode

2.2 Change some of the codes:
※Some functions, macros, types that starts with NS, CG, UI such as NSSet, UIEvent, CGPoint, CGMakePoint need to be changed into something starts with CC :CCSet, CCEvent, CCPoint, CCMakePoint
※It’s OK to use CCLOG here

2.3 Complie && Run in Xcode and Success!

  1. Port the origin project to android

3.1 No need to change any code here!The only thing you need to do is to edit the jni/helloworld/Android.mk file under android folder and add the MenuScene

3.2 Run the build_native.sh

3.3 Refresh the project in Eclipse, Complie && Run in Xcode and Success!

  1. Port the iPhone-android project (we just ported) to Win32

4.1 Create a new project named SimplePortDemo in VS2010

4.2 Add the HelloWorldScene, MenuScene we ported under Mac OS to the project

4.3 Make a little bit of change
※ It’s OK to use CCLOG but you need to cut off the “@” mark

4.4 Complie && Run in Xcode and Success!

Cheers! The whole port job is done now. As you can see from the whole process that you only need to make some small changes to the project to make it support win32, iPhone and android at the same time (at least it is so for a simple demo here) and that is pretty cool right :slight_smile:

PS: A litter bit of problems left here:

  1. The orientation of the project in the Android emulator since to be wrong (I don’t have a real device so…)

  2. Before compiling the Android project, we need to add the MenuScene in the Android.mk manually. What if we have a lot of new files? Do we have to add it all manually?

If you know the answer please let me know :slight_smile: And if you have any questions about the whole process, feel free to ask and I’ll try my best to answer’em …….

Download Source Code
* SimplePortDemo_iPhone_android
* SimplePortDemo_win32

The origin post: http://www.supersuraccoon-cocos2d.com/2011/08/11/how-to-port-a-simple-project-to-win32iphone-and-android/

awesome work!

Just to let you know, the orientation on the real device is also wrong.

sparkart . wrote:

Just to let you know, the orientation on the real device is also wrong.

So do you know why that the orientation is wrong here? Is it a bug or something else?

I don’t know. I haven’t done much investigation, I just wanted to get it onto the Android device. I figured I could figure out how to fix it later when the time comes.