How to Make a Platformer Game with Cocos2D-X

10

Table of Contents

Subscribe
Get email notifications when we release new chapters or use the RSS feed.

Introduction

Chapters
  1. Why Cocos2d-X?
  2. C++ Refresher
  3. Cocos2d-X Basics
  4. C++ vs Objective C
  5. Projects & Build Scripts
  6. Animation & Spritesheets
  7. Tilemap Levels
  8. Box2D Physics
  9. Input & Movement
  10. Powerups & Items
  11. Artificial Intelligence
  12. Ladders, Water, Speech
  13. iAd, Admob, Google Ads
  14. Lua & Javascript
  15. Multiplayer Basics

Outro

Appendices

Share

Cocos2d-X Meta-Project Setup

In this chapter we'll discuss how to create your own Cocos2d-X project files from scratch for iOS, Mac, Android and Windows.

If you'd like, you can download the project files to our complete example game, Paralaxer.

What will you need to follow along?

The iOS and Mac sections assert that you have a Mac computer and have already installed a stable release of Xcode with the iOS SDK. Xcode is a free development environment by Apple and much preferred by many a developer.

The Windows section asserts that you have a genuine copy of Windows XP, Vista, 7 or 8 with Visual Studio Express installed (also a free development environment). You can accomplish this setup on a regular PC or a Mac computer with Boot Camp.

The Android section asserts that you have already installed the Android SDK, NDK and Eclipse (which you now get along with the SDK). You can be ready to build for Android on Windows, Mac or Linux.

Note that the NDK we recommend installing is Google's Android NDK. We used to recommend the NDK from CrystaX, but lately there have been some issues with fopen.

Keep in mind that Xcode, Visual Studio, Eclipse and even Cocos2d-X are updated often. There are new options, build settings and sometimes UI elements have been rearranged. If you run into any significant snags, just be a go-getter, solve your riddle and let us all know the new answer in the comments.

According to a recent survey we took, iOS is the most popular deployment target for Cocos2d-X developers, with Android coming in a close second. So that's where we'll start.

iOS Project From Scratch

There are two ways you can create a Cocos2d-X iOS project from scratch:

  1. Install the Cocos2d-X templates, then do a New Project.
  2. Make a copy of samples/HelloCpp, then open the project and rename.

We'll take a look at both methods.

New iOS Project via Templates

Cocos2d-X comes packaged with a script which installs Xcode project template files for iOS. Just open Terminal, change to your cocos2d-x directory and run the command to install the templates:

cd Desktop/Paralaxer/Code/cocos2d-x/
sudo ./install-templates-xcode.sh -f

Use sudo if you'd like the templates to be installed for all users.

Use the -f flag to automatically remove any existing Cocos2d-X template files and replace them with the newest.

 

Now that you've got the Xcode iOS templates installed, just open Xcode and create a New Project. You'll have the option of choosing one of the Cocos2d-X templates from the iOS category.

Choosing a Cocos2d-X iOS template

Choose one of the Cocos2d-X templates, give your project a name and save it somewhere. You've now got a brand new Cocos2d-X project. Hit the Run button to check out Cocos2d-X's HelloWorld app.

Cocos2d-X's HelloWorld app

As of Cocos2d-X version 2.0.2, what you get is a neat, self-contained project folder. It contains all the Cocos2dx source code files in the libs subfolder.

Cocos2d-X's HelloWorld file structure

This project builds Cocos2dx straight into your binary. In other words, it doesn't compile a static library and then link that into the final binary.

This way is good for customizing the Cocos2dx game engine, as you can edit CCCamera.cpp, for example, as you like. However, it makes upgrading your project to new versions of Cocos2d-X a bit of a hassle. You'l likely have to:

  1. Copy a new version of the Cocos2d-X/cocos2dx folder into your libs folder.
  2. Remove the existing cocos2dx project references from your Xcode project.
  3. Restore them by adding the new cocos2dx folder to your project again.
  4. Remove any unnecessary references (for example, the platform/blackberry folder).
  5. Tune your build settings as necessary.

Xcode Sub-Projects

The alternate way of creating a Cocos2d-X project is to have a reference to the cocos2dx project within your project. In other words, it's a project inside a project (or a sub project).

When creating a project like this, you've got to make the cocos2dx sub-project a Target Dependency and link your binary with its outputted library (e.g. libcocos2dx.a). See the Xcode screenshot below.

A project within an Xcode project

When Cocos2d-X is updated, this sub-project is also updated. Therefore, you don't have to update your original project to the new version of Cocos2d-X. It's a mostly maintenance-free affair.

By making a copy of the Cocos2d-X/samples/HelloCpp, we can start a project like this. The extra benefit of copying the HelloCpp project is that it is already organized for multiple platforms. There's proj.ios, proj.mac, proj.android and proj.win32 folders ready to go.

New iOS Project via Copying

Here's the scoop on how to make a copy of HelloCpp:

  1. Make a new folder for your meta-project (e.g. Desktop/MyHello).
  2. Copy cocos2dx, CocosDenshion and samples/HelloCpp from the main Cocos2d-X folder directly into your meta-project folder.
  3. Rename the samples folder to projects and HelloCpp to MyHello.

You'll end up with a folder looking similar to this:

A copy of Cocos2d-X' HelloCpp meta-project

Now you can open projects/MyHello/proj.ios/HelloCpp.xcodeproj, click on the HelloCpp target and rename it to MyHello (or whatever you like).

Renaming an Xcode project

You'll be presented with a window with options to automatically rename everything in the project to MyHello. Click the Rename button to allow Xcode to do the renaming for you.

Renaming an Xcode project window

Note that my copy of Xcode 4.3 was unable to rename the Prefix.pch and Info.plist files. However, it's easy to do that yourself:

  1. (Finder) Manually rename HelloCpp_Prefix.pch to MyHello_Prefix.pch and HelloCpp-Info.plist to MyHello-Info.plist.
  2. (Xcode) Click the MyHello target and then Build Settings.
  3. Search for HelloCpp and rename the Packaging > Info.plist File and Apple LLVM Compiler - Language > Prefix Header to match your renamed files.
Renaming Info.plist and Prefix.pch

Now prove to yourself that it's your own project. Open Classes/HelloWorldScene.cpp and change the following line:

// create and initialize a label
CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24);

To this:

// create and initialize a label
CCLabelTTF* pLabel = CCLabelTTF::create("My Hello!", "Arial", 24);

Now Build & Run your brand new project:

Running the MyHello iOS Xcode Cocos2dX project

The Mac Project

One of the best parts about creating a meta-project like this is that it re-uses the same game source code for each platform. Because we changed that one line of code to "My Hello!" it will be applied to every other platform we build for. This is where Cocos2d-X really shines.

Open up the projects/MyHello/proj.mac Xcode project and Build & Run. You'll see your "My Hello!" customization.

Running the MyHello Mac Xcode Cocos2d-X project

That's it for the Mac project. If you like, you can rename it to MyHello as you did for the iOS project above.

The Android Command-line Project

Once again the meta-project comes in real handy. We already have an Android command-line project that we can customize.

The Android project is targeted for Android API version 8, or Android 2.2 Froyo. This keeps your Android app the most compatible, especially since the Kindle is based on 2.2.

The proj.android folder is mostly ready to go. We just need to add a makefile for convenience. Open Terminal, switch to your MyHello/projects/MyHello/proj.android directory, and create this makefile (or just download it):

all:
     ./build_native.sh
     ant -Dsdk.dir=/Path/to/your/android/sdk debug
run:
     adb -d uninstall org.cocos2dx.hellocpp
     adb -d install bin/HelloWorld-debug.apk
     adb -d logcat | grep cocos2d
clean:
     rm -rf libs/
     rm -rf obj/
     rm -rf bin/*
     rm -rf gen/
     rm -rf assets/*

Important: make sure to change the /Path/to/your/android/sdk on line 3 to match the path where you installed your Android SDK.

Now, while still in the proj.android directory, you can just run the make command to start building your Android APK file:

Running make in the proj.android folder

When the make command is done, you'll have HelloWorld-debug.apk ready in the bin subfolder. Because it's a bit tricky to get OpenGL ES 2.0 (used by Cocos2d-X) to work in the Android Emulator, I recommend attaching a real Android device via USB and running it that way.

Once you've attached your Android device via USB, just run the make run command, then tap on the HelloCpp app to run it. Here's a screenshot of it running on my Samsung Galaxy S:

Running HelloCpp on a Samsung Galaxy S Froyo Android phone

If you'd like to rename your Android project, there's several files you'll need to edit. First do make clean, then grep -R HelloWorld * and grep -R hellocpp *.

Running grep to look for all proj.android files to rename

Use that list of files to make your edits and remember to also modify the folder structure of src/org/cocos2dx/hellocpp to your structure (e.g. src/com/yourcompany/yourapp).

The Android Eclipse Project

Open up Eclipse and make sure you've got all the Android and C++ plugins installed. If you need some guidance getting Eclipse set up correctly, here's a great tutorial.

Now select File > New > Other... and choose "Android Project from Existing Code".

Creating a new Android project from existing code in Eclipse

Next, choose your proj.android folder with the Browse... button, make sure your org.cocos2dx.hellocpp project is selected and click Finish.

Selecting the proj.android folder and finalizing the new Eclipse project

There you go. You've got org.cocos2dx.hellocpp.HelloCpp in the Package Explorer. Select it, then click the green Play button to launch your app.

If you get errors about @Override and "The method ___ must override a superclass method" then you've got to change your Java compiler compliance level to 1.6. Open Eclipse' preferences to Java > Compiler and select 1.6. Then click "Configure Project Specific Settings..." and do the same for your project.

Wondering where Eclipse stores project file data? It doesn't. Eclipse stores only workspace data.

Note that I don't consider myself an Eclipse expert. Please correct me in the comments if you run into any snags or find a better way to set up your Eclipse projects. I will then update this chapter.

The Windows Project

The first step here is to get the MyHello project onto a Windows system. I like to just zip up the MyHello directory, reboot my Mac computer into Windows via Boot Camp, then extract all to the Desktop.

Now that you've got the MyHello project on Windows, open up Visual C++ (I'm currently using Visual Studio Express 2010 for this tutorial). Choose File > Open > Project/Solution... and open your MyHello/projects/proj.win32/HelloCpp.vcxproj. This will create a new solution with the HelloCpp project.

Next, right click on your solution in the Solution Explorer, choose Add > Existing Project, navigate to your MyHello/cocos2dx/proj.win32 folder and select cocos2d.vcxproj. Repeat the process to add MyHello/CocosDenshion/proj.win32/CocosDenshion.vcxproj.

Now you have a the HelloCpp solution with the 3 sub-projects:

  1. HelloCpp
  2. libcocos2d
  3. libCocosDenshion

Next we have to set up the solution and project properties.

First, right click on the HelloCpp solution (not the HelloCpp project) and choose Properties. Under Common Properties > Project Dependencies, select HelloCpp from the Project drop-down, check the boxes next to libcocos2d and libCocosDension, then click Ok. This will ensure that the libcocos2d and libCocosDenshion projects are built before the HelloCpp project.

Making libcocos2d and libCocosDenshion dependencies of the HelloCpp Win32 Cocos2dx project

Now right click on the HelloCpp project (not the solution) and choose Properties. Select All Configurations from the Configuration drop-down.

Open Configuration Properties > C/C++ > General, edit the Additional Include Directories and change all $(SolutionDir) to $(SolutionDir)..\..\..\. Click Ok to save and close the properties for the HelloCpp project.

Setting the additional include directores for a Cocos2d-X win32 project

It's a similar process for the libcocos2d project. Right-click it and choose Properties. This time open Configuration Properties > Build Events > Pre-Link Event. Edit the Command Line option and change the $(SolutionDir) to $(SolutionDir)..\..\..\:

Setting the pre-link event for the libcocos2d project

That's it. You now have a Win32 solution ready to go. Just click the green Play icon to Build and Start Debugging.

Here's a screenshot of MyHello running on Windows XP (it also works on Vista, Windows 7 and 8):

Running MyHello on Wind32

Conclusion

By now you've gone through creating a Cocos2d-X meta-project that builds and runs on iOS, Mac, Android and Windows. Congratulations.

The exciting part about it all is that the same file, HelloWorldScene.cpp, drives most of the content for this little app. Changing that one line from saying "Hello World" to "My Hello!" worked on all those platforms without any further edits.

That's all for this chapter.

Got questions? Leave a comment below.

Stay tuned. We are writing the next chapter in this free online book. If you'd like, you can subscribe to be notified when we release new chapters.

Comments


61 comments on “Cocos2d-X Meta-Project Setup

  1. Painache on said:

    Great chapter. I followed the instructions and created the meta-projects without any snags in Cocos2d-2.0-x-2.0.3.

    Thank you very much, man.

  2. Jesús Bosch on said:

    Hi,

    Great tutorial… but I’m frustrated with Android. The tutorial doesn’t show how to enable the debugging on Android, something that is very important. How are we supposed to develop Android games if we can’t debug them? This missing feature makes it impossible.

    • Nat Weiss on said:

      First, it is possible to debug your Android games with CCLog statements. It’s not the recommended way to debug, but it will get you by.

      Android debugging should be under the Eclipse section. You ought to be able to follow the instructions there to get the projects in your workspace, and then debug from there. As I said, I’m not an expert with Eclipse. Can anyone help us out with a few Cocos2d-X Eclipse debugging tips? I’d like to update this chapter.

  3. Loc Nguyen on said:

    I create project on windows first , and then create meta-project ( copy project to new folder Desktop/MyMetaProject ) and I success with run on windows , but when I run make with terminal , I got an error

    $ make
    ./build_native.sh
    NDK_ROOT = E:/Download/Android/android-ndk-r8b
    COCOS2DX_ROOT = /cygdrive/c/Users/Vinh Loc/Desktop/SuperTeo meta-project/MyProject/SuperTeo/proj.android/../../..
    APP_ROOT = /cygdrive/c/Users/Vinh Loc/Desktop/SuperTeo meta-project/MyProject/SuperTeo/proj.android/..
    APP_ANDROID_ROOT = /cygdrive/c/Users/Vinh Loc/Desktop/SuperTeo meta-project/MyProject/SuperTeo/proj.android
    Using prebuilt externals
    Android NDK: ERROR: You NDK_MODULE_PATH variable contains spaces
    Android NDK: Please fix the error and start again.
    make[1]: Entering directory `/cygdrive/c/Users/Vinh Loc/Desktop/SuperTeo meta-project/MyProject/SuperTeo/proj.android’
    /cygdrive/e/Download/Android/android-ndk-r8b/build/core/setup-imports.mk:27: *** Android NDK: Aborting . Stop.
    make[1]: Leaving directory `/cygdrive/c/Users/Vinh Loc/Desktop/SuperTeo meta-project/MyProject/SuperTeo/proj.android’
    makefile:2: recipe for target `all’ failed
    make: *** [all] Error 2

    What can I do now :(

    • Nat Weiss on said:

      Not to worry. The error message “Your NDK_MODULE_PATH variable contains spaces” says it all. The problem is in these lines of build_native.sh:

      echo “Using prebuilt externals”
      “$NDK_ROOT”/ndk-build -C “$APP_ANDROID_ROOT” $*
      “NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/prebuilt”

      Because your COCOS2DX_ROOT contains spaces (“Vinh Loc” and “SuperTeo meta-project”) it is causing this line to fail. This is actually a bug in Cocos2d-X which can be fixed. They have fixed the issue on many of the other lines by wrapping the variables in quotes, like this:

      mkdir “$APP_ANDROID_ROOT”/assets

      Can you please post in the forums of cocos2d-x.org so this issue can be resolved?

      In the meantime, you can easily get it working on your system by putting your meta-project in a safe, spaces-free directory, like /cygdrive/c/Projects/MyProject/

    • Loc Nguyen on said:

      Thanks ^^ it’s work now :)

  4. Loc Nguyen on said:

    Another error here

    make[1]: Leaving directory `/cygdrive/d/SuperTeoMetaProj/MyProject/SuperTeo/proj.android’
    ant -Dsdk.dir=”C:/Program Files (x86)/Android/android-sdk” debug
    /bin/sh: ant: command not found
    makefile:2: recipe for target `all’ failed
    make: *** [all] Error 127

    I’m using cygwin terminal. So what should I do now :(

    • Nat Weiss on said:

      Your error is: “ant: command not found.” A google search reveals some helpful resources:

      http://stackoverflow.com/questions/3858732/installing-ant-on-cygwin

    • Loc Nguyen on said:

      Thanks , after a lot of work I finally done with meta project :D
      Thanks for your article :D I’m waiting for next chapter , I’m new to cocos2d-x and very exciting with it :D

  5. Painache on said:

    Hi
    A new request here. I want to create a meta-project with Box2D support and extensions(cocosbuilder reader/scroll view/edit box …etc) support.
    How can I do that?

    • Nat Weiss on said:

      Great question. Well, it seems like a simple way to do that would be to just copy the TestCpp project instead of HelloCpp. Make sure to also copy the extensions folder into your meta-project directory. Start with the iOS & Mac projects and follow the same general guidelines in this post for Android & Windows.

  6. Jackie on said:

    First I want to thanks for your article . Second I want to ask can our meta-project port to BlackBerry ? And If yes, can you show me a way ? Cause I’m interested with BB and want to port my game to BB tablet os :D

    • Nat Weiss on said:

      Yes, by following the instructions in this article, you will already have a BlackBerry project in your MyHello/projects/MyHello/proj.blackberry folder. Sorry, but I’m not familiar with BlackBerry, so you’re going to have to take it from there.

  7. Excellent tutorial. We have been developing with Unity for a while and recently switched to Cocos2Dx.
    It’s nice to see how far Cocos2D community has come along in last 3 years.

  8. Alan Price on said:

    Great job. I went through several different trials on getting a multi-platform project started for cocos2d-x. This is definitely the easiest to get working and is probably the most future proof as it leverages the samples provided with Cocos.

    I will see how things go moving forward. I’m wondering as I start to add new files how many places I will need to change to keep the projects moving together in sync.

    I decided to rename projects as I went through the example. The android project was definitely the most painful. There are also a couple references to HelloCpp that will want to be changed and definitely the structure of the src directory is critical (that tripped me up as somehow I missed your comment at the end of the command line section).

  9. Pingback: Integrating Photon 3.0.4.0 with Cocos2d-2.0-x-2.0.3 in xCode 4.5.1 for Android and iOS (Part 1: iOS) « codebygeorgeguy

  10. Pingback: Integrating Photon 3.0.4.0 with Cocos2d-2.0-x-2.0.3 in xCode 4.5.1 for Android and iOS (Part 2: Android) « codebygeorgeguy

  11. Bagusflyer on said:

    I got the following error:

    The import org.cocos2dx.lib.Cocos2dxActivity can not be solved.

    My Cocos2d-x version is 2.0.4 and the directory structure is exactly the same as you mentioned in the blog. Any idea? Thanks.

  12. Patricio on said:

    Hello Nat Weiss from Spain:

    First congratulations for this book. It’s too helpful and instructive.

    I have a doubt with this chapter.
    I don’t have a Mac computer and I created my meta-project starting from a PC computer with Windows XP.
    Like windows user, then I followed this tutorial from cocos2d-x web:
    http://www.jesusbosch.com/2012/06/how-to-set-up-android-and-win32-cocos2d.html

    I will try one’s luck with Android first. And if my game has some success, then I will try with iOS.
    Do you know if I will have problems when I want to build Mac project starting from windows user tutorial?

    Thanks

    • Nat Weiss on said:

      Hi Patricio,

      Actually, if you create a meta-project like in this tutorial, you shouldn’t have any problems transitioning from Windows to Mac. You’ll have all the files for a Mac project all ready to go.

  13. Just an FYI; If you’re silly like me and copy-n-paste the makefile contents, you’ll end up with an error like this:

    makefile:2: *** missing separator. Stop.

    makefile requires TABs, not spaces.

  14. Hi Nat, I have “The import org.cocos2dx cannot be resolved” at “import org.cocos2dx.lib.Cocos2dxActivity;” line

    I have no src/org/cocos2dx/lib/Cocos2dxActivity.java because in samples/HelloCpp didn’t exists this java. I forgot anything?

    tx in advance

  15. Excellent tutorial, I followed the ‘New iOS Project via Copying’ section however one minor issue in Xcode 4.5 was I could not rename the project without git support. This can easily be sorted with a ‘git init’ via command line in the project root folder e.g. ‘MyHello’

    In Xcode 4.5 all files are renamed correctly however you still need to update the ‘plist’ name in build settings.

  16. rousing on said:

    Great tutorial,
    As also requested by Painache. Is it possible to update it with Box2d and extensions please ?

    thank you

  17. Pingback: box2d debug drawing in a cocos2dx environment – blog.noomieware.de

  18. Lance Gray on said:

    I tried several ways to make it run on Android but I can’t seem to make it work.

    I followed the “New iOS Project via Copying” part and the “The Android Command-line Project”. It compiles properly now but I can’t run “make run” and is giving me the following error:
    xxxxx-MacBook-Pro:proj.android xxxxx$ make -f makefile1 run
    adb -d uninstall com.mygames.appname
    make: adb: No such file or directory
    make: *** [run] Error 1

    If I try to comment the line “adb -d uninstall com.mygames.appname”, I get the following error:
    xxxxx-MacBook-Pro:proj.android xxxxx$ make -f makefile2 run
    adb -d install bin/appname-debug.apk
    make: adb: No such file or directory
    make: *** [run] Error 1

    I looked at the bin directory and the APK file is there.
    I tried using Eclipse but I am getting the “The import org.cocos2dx cannot be resolved” error in the line “import org.cocos2dx.lib.Cocos2dxActivity;” of the “src/com/mygames/appname/main.java” file. The file “src/org/cocos2dx/lib/Cocos2dxActivity” does not exist.

    Did I just miss something? I’m using Xcode 4.5, Eclipse Indigo, and cocos2d-x-2.0.4 on a Macbook Pro ( Mav OS X 10.8 )

    • Nat Weiss on said:

      What happens if you comment out the “import org.cocos2dx.lib.Cocos2dxActivity;” line?

    • Lance Gray on said:

      There are still errors on the line ‘public class appname extends Cocos2dxActivity’. I think the problem here is that it can’t find the class Cocos2dxActivity anywhere in the project. I’ve had it working with the makefile method but I needed to debug my app and Eclipse won’t compile because of that error.

    • Lance Gray on said:

      I have fixed the error by going to Project Properties -> Java Build Path -> Source and then linking “cocos2dx/platform/android/java/src”

      I use Eclipse Juno, so it might not appear on older versions.

    • Nat Weiss on said:

      Cool.

  19. Pingback: Cocos2D-x入门教程 | 应用中国

  20. Something worth mentioning for Android: You need to “build” the project before importing into Eclipse. This basically involves running the build_native.sh script thru cygwin.

    If you are facing errors or app crash on launch in Eclipse, you probably haven’t built the code (and hence it can’t find the library).

    Also, if you see “library not found”, you probably need to import again (don’t use copy to workspace option)

  21. Hi,
    Anyone able to setup the ‘myhello’ android project on a windows pc – no access to a mac over xmas period.

    Problem I have, is I can’t follow the steps past installing the Android + Eclipse tools as I dont have the files,config/setup that is listed in the guide so cant create the iOS meta project etc and its not clear to me how to copy from the paralaxer code to create a new androind meta project on a windows only machine (Though I do have the paralaxer ofc, and the regular android sample apps work)

    Cheers, being thick through the post xmas fog..hehe :)

    Andy

    • Nat Weiss on said:

      Hey Andy,

      There’s really not that much that Xcode is doing to the project. You might just be able to follow along and wing it. Maybe give it another shot? Good luck.

  22. I followed the tutorial up to the android segment and had success. I then renamed all my files and went a few steps further as some things still were saying HelloCpp. I honestly don’t remember the exact steps as it was somewhat trial and error. I know for a fact I did Project>Refactor>Rename, changed the ‘app_name’. Everything seemed fine and was running with the correct app labels and names inside of the IDE and on the device. Then I hopped in xCode to just do a quick change as a test and tried to re ‘make’ the build. At this point I now get the error:

    R.java was modified manually! Reverting to generated version!

    01-15 15:37:26.775: E/AndroidRuntime(10606): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.company.renamed/com.company.renamed.Renamed}: java.lang.ClassNotFoundException: Didn’t find class “com.company.renamed.Renamed” on path: /data/app/com.company.renamed-2.apk

    Any ideas? What is the correct process for completely renaming the project from HelloCpp to whatever you want in all occurrences. Meaning so it displays correctly in Eclipse(Project Tree), all the paths like com.company.appname are synced and there is no more occurrence of the copied template HelloCpp. Once thats done how do you recompile updates and continue on.

    • Nat Weiss on said:

      Hey Mike, I really don’t know the answer as I’m not an Eclipse expert. The way I would do it is to manually rename all occurrences of com.yourcompany.yourproject on the commandline using grep to find them. Then you could try re-importing the project into Eclipse?

    • sortris on said:

      Try to restart Eclipse. It helped to me xD I can’t believe it, but it works.

  23. Dang, i’m really confused right now!

    I’m using Windows 7 and i want to create a project that will run on both Android and iOS. How do i do that?

    You guys use a Mac to create a project to iOS, a PC with Linux to create a project do Android and a PC with Windows to create a project do Windows?!

    • Nat Weiss on said:

      Pedro. You need a Mac computer for iOS and you need Windows for win32 builds. Other than that you can build Android on any system. So, in your case, if you are only on Windows 7, you can build for Android and Windows. You’ll need to pick up some sort of Mac machine to build for iOS and Mac.

  24. I created a project via copying. Unforunately I get an error. “Lexical or Prepocessor Issue ‘cocos2d.h’ file not found” I tried restarting Xcode deleting derieved data.

    • I forgot to mention.. I am using Xcode 4.6 and the latest cocos2d-x 2.1.1 stable build

    • Nat Weiss on said:

      Why can’t it find cocos2d.h? Is there something wrong with the header search paths for the project?

    • Permanente on said:

      Hello,I’m also on xcode 4.6 and I’m having a similar issue. Make sure your adding the cocos2dx and CocosDenshion folders to your project once you have xcode open. I did that and got rid of the “cocos2d.h missing”error, but now im getting several other missing header file errors such as “platform/CCPlatformMacros.h” but after digging around in the xcode file browser panel, i found that they are included in the project properly.

      After much messing around im pretty stumped. The samples/hellocpp projects work fine inside the original extracted version of cocos2d that i downloaded, but as soon as they are copied out into a new folder structure like the one in your tutorial the xcode projects seem to no longer work. as a matter of fact, the “cocos2dx.xcodeproj” sub project of the “HelloCpp” project seems to have some sort of error, its in red in the xcode file browser panel and i cant seem to find the source of the error.Any help would be much appreciated, your tutorial is great, now if only i could get it to work! Thanks!

    • Permanente on said:

      Hi again, i feel stupid. I resolved this issue a few minutes after making my last post. instead of following the recommended file structure of “projects/MyHello” i followed the way it was set up in the original download of cocos2d-x and made it “projects/cpp/Myhello” and everything was resolved. Not sure why though. Im guessing somewhere there is a file path the project is being told to follow to find the needed libraries, but i dont know where. Anyone have a clue why this would fix this problem?

    • Nat Weiss on said:

      Hmm. They might have changed the folder structure in the latest Cocos2d-X. I will update soon.

  25. Pingback: cocos2d-x環境構築メモ2 » MOKYN

  26. Just Games on said:

    -post-package:

    -do-debug:
    [zipalign] Running zip align on final apk…
    [echo] Debug Package: /Users/macmac/Desktop/MyHello/projects/MyHello/proj.android/bin/HelloWorld-debug.apk
    [propertyfile] Creating new property file: /Users/macmac/Desktop/MyHello/projects/MyHello/proj.android/bin/build.prop
    [propertyfile] Updating property file: /Users/macmac/Desktop/MyHello/projects/MyHello/proj.android/bin/build.prop
    [propertyfile] Updating property file: /Users/macmac/Desktop/MyHello/projects/MyHello/proj.android/bin/build.prop
    [propertyfile] Updating property file: /Users/macmac/Desktop/MyHello/projects/MyHello/proj.android/bin/build.prop

    -post-build:

    debug:

    BUILD SUCCESSFUL
    Total time: 9 seconds
    /Users/macmac/Desktop/MyHello/projects/MyHello/proj.android/makefile: line 5: adb: command not found
    /Users/macmac/Desktop/MyHello/projects/MyHello/proj.android/makefile: line 6: adb: command not found
    /Users/macmac/Desktop/MyHello/projects/MyHello/proj.android/makefile: line 7: adb: command not found
    static-246:proj.android macmac$

    im getting this error and im working on Mac OS…. Pls help me out from this problem.

    • Nat Weiss on said:

      You might need to put platform-tools in your path:

      http://stackoverflow.com/questions/7609270/not-able-to-access-adb-in-os-x-through-terminal-command-not-found

  27. Pingback: Cocos2d-X Meta-Project Setup Tutorial for iOS, Android, Mac & Windows | Programming Cocos2D with iPhones and iPads

  28. Pingback: » #1GAM - dpk's weblog

  29. Pingback: M I C H A E L – C H I N E N » Cocos2D-X: Creating an iOS/android dual-platform project

  30. Pingback: Cocos2d-x 的项目管理 | 12 6 17

  31. Fernado Javier Fernandez on said:

    Hi, great tutorial. I´m new with cocos2d-x and I´m trying to run helloworld on android using eclipse, but its really frustrating. First of all got a lot of troubles with the libraries and the configuration, when I was ready to build and launch the app, the emulator in eclipse took a lot of time getting started and it is very slow (imagine debugging your game on it), finally when it got started the application didn´t launched, I was thinking it will probably be the way I´ve had created the project but not I did it using native_build.sh, then I decided to run it on a virtual machine using the image of a assus tablet provided by the project android-x86 which is faster than the native emulator and again I try to deploy the app and it didn´t start in the emulator giving me an error in the console that a library could not be found. What I´m doing wrong? please help me.

    • Nat Weiss on said:

      Which library?
      What happens if you just run build_native.sh from the commandline?

  32. Pingback: quick-cocos2d-x 之环境搭建 | 12 6 17

  33. Carlos on said:

    This is giving me the creeps…

    I’m trying to do a cocos2d-x project in order to do the android version of my finish cocos2d ios game.

    I’ve been looking for tutorials and I can’t even have the base project…

    I have done the same as you say in the tutorial (only I added the box2d folder) but I’m stuck at this “Now, while still in the proj.android directory, you can just run the make command to start building your Android APK file:”

    Run the make command?? HOW??, If I open the terminal in the proj.android folder and just write “make” and press enter, i get an error
    make
    make: *** No targets specified and no makefile found. Stop.

    I don’t know what to do to have a base project with cocos2d-x and box2d…. I only need the base project, and then start coding my game in eclipse…

    This is giving me the creeps, I don’t need mac, or windows or ios, I just want to have the cocos2d-x project in eclipse, and code there the game… (cause I already have finished my cocos2d ios game)

    Please help!! Thanks

    • Nat Weiss on said:

      Carlos, pay attention to the part about the makefile. You need to download it or create your own so that the make command knows what to do.

  34. sts2055 on said:

    For those building the project for Windows. I had to add libcocos2d as a dependency to libCocosDenshion for it to work.

  35. sts2055 on said:

    First of all, thank you for this great book!
    It really helps and I even managed to run my first ever windows program, yay!
    Maybe somebody can help me with this one, though:
    I got the program working in Visual Studio, however, when I want to share it with my pal, when I click the .exe in the Debug.win32 folder, the program runs, I can see the fps indicator and all, but it doesn’t load any Sprites. How come?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

HTML tags are not allowed.

Brought to you by the iPhone Game Kit.