★ TouchArcade needs your help. Click here to support us on Patreon.

How to port a simple project to win32,iPhone and Android

08-11-2011, 11:35 AM
#1
Joined: Apr 2011
Location: China
Posts: 32
How to port a simple project to win32,iPhone and Android

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

http://www.supersuraccoon-cocos2d.co...-under-mac-os/

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;

http://www.supersuraccoon-cocos2d.co...ploy-tutorial/

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!

2. 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!

3. 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!


4. 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

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 And if you have any questions about the whole process, feel free to ask and I'll try my best to answer'em .......

SimplePortDemo_iPhone_android:
http://dl.dropbox.com/u/30871449/Web...ne_Android.zip

SimplePortDemo_win32:
http://dl.dropbox.com/u/30871449/Web...Demo_Win32.zip

PS: If you are interested you can check it here:
http://www.supersuraccoon-cocos2d.co...e-and-android/
08-11-2011, 11:37 AM
#2
or use Unity and its one click
08-11-2011, 07:09 PM
#3
Joined: Apr 2011
Location: China
Posts: 32
08-11-2011, 07:42 PM
#4
Time vs money I guess for ports. You can do a Mac app, win app or webplayer for free it does cost for android and iOS tho. Sorry for going off topic. Great initial post.