cocos2d的配置

来源:互联网 发布:小精灵字幕软件 编辑:程序博客网 时间:2024/06/07 06:25

今天下午将cocos2d的win32版本配置好了。

引述官网的教程。自己有点心得,学会看英文文档。

Chapter 1 - How to Create a New cocos2d-x project on multi-platforms

Today we will start a tutorial on how to port the famous Cocos2dSimpleGame from objc to c++, using cocos2d-x engine, then run it on win32/iphone/android/wophone multi-platforms. The Cocos2dSimpleGame is written byRay Wenderlich. Almost every beginner of cocos2d-iphone has read his tutorial series.

First of all, you need to download the last stable version of cocos2d-x from http://download.cocos2d-x.org. It’s cocos2d-0.99.5-x-0.8.2 when I write this article, and then update the game source to 0.8.5. The infix 0.99.5 means this c++ port is based on the parent cocos2d-iphone 0.99.5, and the suffix 0.8.2 is the version of our cocos2d–x port.

The source of Cocos2dxSimpleGame is here https://code.google.com/p/cocos2d-x/downloads/detail?name=Cocos2dxSimpleGame-0.8.5.zip, I have tested it with cocos2d-0.99.5-x-0.8.5.

Let’s begin. You can jump to your platform directly from this catalogue.

  • Chapter 1 - How to Create a New cocos2d-x project on multi-platforms
    • 1. start with win32
      • 1.2 install Wizard on VisualStudio
      • 1.3 Create a new cocos2d-win32 project
      • 1.4 Build and Run
      • 1.5 Portal for unlucky guys
    • 2. Start with WoPhone
    • 3. Start with iPhone
    • 4. Start with Android
      • 4.1 Under windows
      • 4.1.1 Create project
      • 4.1.2 Build native code
      • 4.1.3 Import project to eclipse
      • 4.1.4 Build java code and run
      • 4.2 Under linux

1. start with win32

cocos2d-win32 port is well tested on WinXP + VistualStudio2008/2010. But in vista/win7, I can not promise it runs well. Here’s a protal for unluck guys who cannot run this tutorial correctly on cocos2d-win32 port…

1.2 install Wizard on VisualStudio

After download and unzip the package, you can go into cocos2d-x folder, click “build-win32.bat” to compilate the whole project, than click "install-templates-msvc.bat" to install the wizard. The bat scripts adapt vs2008 or 2010 automaticlly. For more detail, please read this document Cocos2d-x Application Wizard for Visual Studio User Guide
It’s the screenhost of install-templates-msvc.bat succedd in Microsoft VistualStudio 2008 environment.

1.3 Create a new cocos2d-win32 project

Now open cocos2d-x/cocos2d-win32.vc2008.sln via VS2008, we can see the libs here.

Right click the “Solution ‘cocos2d-win32.vc2008’ “, then “Add->New Project”,

select "cocos2d-x -> cocos2d-win32 Application", fill in the name "Cocos2dxSimpleGameForWin32", and use the default location setting.
NOTED: the location of games must stay in the directory of cocos2d-x root in win32 & wophone port.

Click “OK -> Next”, uncheck Box2D because Cocos2dSimpleGame will not use physics. Make sure “SimpleAudioEngine in CocosDenshion” is checked, then “Finished”.

1.4 Build and Run

Now we can see the “Cocos2dxSimpleGameForWin32.win32” is created! Check the dependencies, our game depends on libcocos2d & libCocosDenshion now.

Well, build and run it, if you are not unlucky enough, you can see

1.5 Portal for unlucky guys

I can not promise that everyone can run this HelloWorld successfully on win32. Because the cocos2d-win32 port is based on the PowerVR OpenGL ES 1.1 SDK for PC Emulation (Windows ista/XP version) 
http://www.imgtec.com/PowerVR/insider/sdkdownloads/index.asp#GLES1b 
We integrated the PowerVR libraries in the path 
cocos2d-x-root/cocos2dx/platform/win32/third_party/libraries

So:
  • For win7 users: PowerVR has not release Windows7 port yet. But you still can have a try. Many win7 users in cocos2d-x community successfully run this case.
  • For winxp/vista users: If HelloWorld crashed at any glXXX or eglXXX function, please update the driver of your video card, goto the website of NVIDIA/ATI/INTEL to look for a last driver
  • For unlucky users: You can create cocos2d-x project in XCode manually, or goto church/temple to look for a better luck :p

2. Start with WoPhone

If you are a wophone developer, the steps of win32 above also fits you. There are only 3 differences:
  1. you must locate cocos2d-x-root in D:/Work7, wophone has a strict app path requirement.
  2. please open D:/Work7/cocos2d-x/cocos2d-wophone.sln via VS2008 instead of cocos2d-win32
  3. select “cocos2d-wophone application” in the “Add New Project” dialog, just like this

And the result of cocos2d-wophone HelloWorld is

3. Start with iPhone

We have templates for xcode now since version 0.8.2。 You can create cocos2d-x projects as easy as cocos2d-iphone projects.

At first, goto the root of cocos2d-x folder, then run the install-templates.sh in the mac shell 

 sudo ./install-templates-xcode3.sh 

After the version 0.8.2, it may be install-templates-xcode.sh, and you can choose your xcode version, xcode3 or xcode4. 
After the installation finisehd, you can start the Xcode, then click "Create a new Xcode project". You can see this dialog

Select "cocos2d-x application", then click "choose", type in the project name. The cocos2d-x project will created by xcode for you.

Notice that, the cocos2d-x project for iOS can be create in anywhere as you wish. The wizard in xcode will copy the libraries of all cocos2dx, CocosDenshion, etc, into the project folder. This is different from the wizard for win32 & wophone in VisualStudio.

Ok, then build and run, you could see the HelloWorld scene as follows,

4. Start with Android

The project of android for ndk contains two parts, one for java, and the other for c++. We would run create-android-project.bat(or create-android-project.sh under linux) to create android ndk project.

4.1 Under windows

4.1.1 Create project

"create-android-project.bat" is under the root of cocos2d-x. You should do some changes to work under your environment.

Change some macros in create-android-project.bat to work in your environment.
  • set _CYGBIN=C:\cygwin\bin 
    The path of cygwin bin
  • set _ANDROIDTOOLS=D:\anroid\android-sdk-windows\tools 
    The path of android sdk tools
  • set _NDKROOT=D:\anroid\android-ndk-r4-crystax 
    The root of ndk

Now you can run "create-android-project.bat" to create an android project: 
Goto the root of cocos2d-x, double click create-android-project.bat, input the project name and target id. Just like this

After version 0.8.2, you may be asked to enter the package path, the path format is like this: org.coco2dx.Cocos2dxSimpleGameForAndroid. 
The target ids are different in different environment, you should be sure to input valid target id. Now cocos2dx supports 
2.1-update1 and Android 2.2, other versions have not been tested.

4.1.2 Build native code

Now you can see a folder named "Cocos2dxSimpleGameForAndroid" under the root of cocos2d-x. Run your cygwin, and goto 
"Cocos2dxSimpleGameForAndroid/android", then run "build_native.sh".

4.1.3 Import project to eclipse

Run your eclipse, click File -> New -> Project -> Android Project, and import the project like this

4.1.4 Build java code and run

Right click the project and select "Build Project", then right click the project and select "Run As" -> "Android Application". Then you can see the result:

4.2 Under linux

You should run "create-android-project.sh" to create android project, the others are the same as under windows.

You should define some environment variables to run "create-android-project.sh" under your environment. 
Initialize some environment variables.
  • NDK_ROOT 
    The root of ndk.
  • ANDROID_SDK_ROOT 
    The root of android sdk.

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 龙之谷账号忘了怎么办 不花钱的排风除湿怎么办 苹果平板id密码忘了怎么办 苹果平板忘记id及密码怎么办 饥荒抓到的兔子怎么办 苹果手机下载不了王者荣耀怎么办 ipad登录显示验证失败怎么办 苹果手机系统内存太大怎么办 ipad玩游戏没声音怎么办 微信活跃度低怎么办 想开通淘宝直播粉丝不够怎么办 下巴长泡泡还痒怎么办 脚起泡泡很痒怎么办 脚痒还有小泡泡怎么办 外阴长了肉疙瘩怎么办 嘴巴里泡泡破了怎么办 脚上泡泡破了怎么办 脸被自己扣破了怎么办 6s安装不了软件怎么办 苹果6s特别卡怎么办 苹果手机4g网慢怎么办 大王卡玩王者卡怎么办 荣耀7c手机卡顿怎么办 华为6x手机卡顿怎么办 荣耀7c手机老卡怎么办 苹果6打王者卡怎么办 电脑玩游戏显示显卡不行怎么办 笔记本玩游戏显卡不行怎么办 笔记本玩英雄联盟有点卡怎么办 英语考试作文抄了阅读理解怎么办 qq账号被盗怎么办很久了 想玩线上德州没有渠道怎么办 手机玩久了头晕怎么办 玩3d游戏头晕恶心怎么办 win10打cf没声音怎么办 英雄联盟玩家尚未准备就绪怎么办 玩手机想吐应该怎么办 玩手机多了头晕怎么办 玩cf老是无响应怎么办 玩穿越火线好卡怎么办 绝地求生画质卡顿怎么办