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

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?

First of all, you'll need to download Cocos2d-X. This tutorial is written for version 3. There's also an older version of this chapter maintained for version 2.

The iOS and Mac sections assert that you have a Mac computer and have already installed a stable release of Xcode. 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 with Visual Studio installed. You can accomplish this setup on a regular PC or use a Mac computer with Boot Camp.

The Android section asserts that you have already installed the Android SDK (which includes Eclipse) and NDK. Make sure to install the latest platform-tools, build-tools and API 13 from the Android SDK Manager. With this setup, you can 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 problems, please let us know how you solved them 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's now a very simple way to create a Cocos2d-X iOS project from scratch. Just open Terminal, change to your cocos2d-x directory and run the command to create a new multi-platform project:

cd Desktop/cocos2d-x-3.0/
./tools/project-creator/create_project.py \
   -p MyGame \
   -k com.MyCompany.AwesomeGame \
   -l cpp

The -p option sets the name of your project, the -k option sets the identifier, and the -l option sets the language. We use cpp here to create a C++ project. You can also use lua and javascript.

 

You've now got a brand-new, multi-platform game project called "MyGame" inside the projects folder.

Open up projects/MyGame/proj.ios_mac/MyGame.xcodeproj. Select "HelloCpp iOS" from the scheme dropdown (it will probably say "build-all-libs Mac" initially) and hit the Run button to check out Cocos2d-X's HelloWorld app.

Cocos2d-X's HelloWorld app

You probably noticed when you selected "HelloCpp iOS" from the schemes dropdown that there are many non-runnable schemes to choose from. You can hide all these non-runnable schemes. Just select "Manage Schemes..." from the scheme dropdown, uncheck the Show box next to all but "HelloCpp iOS" and "HelloCpp Mac" and click OK.

Hiding non-runnable schemes in Xcode

Xcode Sub-Projects

Let's take a look at the project behind the scenes. It's actually quite elegant.

First of all, Cocos2d-X is included as a sub-project. It makes available many different targets that can be built and included in your game. These include the cocos2dx library for iOS & Mac, the CocosDenshion sound engine for iOS & Mac, the Box2d & Chipmunk physics engines, and many other libraries.

These libraries are included in the HelloCpp project as dependencies and the resulting library files are linked into the binary. View this for yourself by clicking HelloCpp from the project drawer and then clicking Build Phases.

 

Building a project this way makes upgrading a snap. Since all the libraries are included as a single sub-project, when Cocos2d-X is upgraded the MyGame project does not have to be edited. Just move MyGame to the new Cocos2d-X projects folder and that's it.

Customizing the Project

Now let's customize the project a little bit. Open Classes/HelloWorldScene.cpp and change the following line:

// create and initialize a label
auto label = LabelTTF::create("Hello World", "Arial", 24);

To this:

// create and initialize a label
auto label = LabelTTF::create("My Hello!", "Arial", 24);

Now Build & Run your project:

Running the MyHello iOS Xcode Cocos2dX project

The label now says "My Hello!" instead of "Hello World". You've successfully proven the project is your own.

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.

The Mac project is already a part of the iOS project that we've been working on. Just select "HelloCpp Mac" from the schemes dropdown and Build & Run. You'll see your "My Hello!" customization.

Running the MyHello Mac Xcode Cocos2d-X project

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 13. Think of this like a minimum deployment target. Your game will run on Android 3.2 Honeycomb or newer.

The proj.android folder is mostly ready to go. We just need to add a makefile for convenience. Open Terminal, switch to your MyGame/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 com.MyCompany.AwesomeGame
     adb -d install bin/MyGame-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 MyGame-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 MyGame 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

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.

Follow the Eclipse instructions in MyGame/proj.android/README.md. There's a few things you'll need to setup to ensure Cocos2d-X compiles correctly.

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 project is selected and click Finish.

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

There you go. You've got a link to your game 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.

The Windows Project

The first step here is to get the MyHello project onto a Windows system. I like to just zip up the entire Cocos2d-X 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++ with cocos2d-x/projects/MyGame/proj.win32/HelloCpp.sln. Next, click the green Play icon to Build and Start Debugging.

Here's a screenshot of MyGame running on Windows. Note that it already has our "My Hello!" customization applied.

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.

Next Chapter >

Comments


80 Responses to “Cocos2d-X Meta-Project Setup”

  1. Painache

    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.

    Reply
  2. Jesús Bosch

    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.

    Reply
    • Nat Weiss

      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

    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 :(

    Reply
    • Nat Weiss

      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/

  4. Loc Nguyen

    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 :(

    Reply
  5. Painache

    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?

    Reply
    • Nat Weiss

      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

    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

    Reply
    • Nat Weiss

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

    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.

    Reply
  8. Alan Price

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

    Reply
  9. Bagusflyer

    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.

    Reply
  10. Patricio

    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

    Reply
    • Nat Weiss

      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.

  11. Darryl

    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.

    Reply
  12. Jorge

    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

    Reply
  13. Martin

    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.

    Reply
  14. rousing

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

    thank you

    Reply
  15. Lance Gray

    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 )

    Reply
    • Lance Gray

      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

      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.

  16. Arjun

    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)

    Reply
  17. Andy

    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

    Reply
    • Nat Weiss

      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.

  18. Mike

    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.

    Reply
    • Nat Weiss

      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

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

  19. Pedro

    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?!

    Reply
    • Nat Weiss

      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.

  20. Xazen

    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.

    Reply
    • Xazen

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

    • Nat Weiss

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

    • Permanente

      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

      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?

    • Benjamin

      Yeah, you should definitely update that!
      I spend quite a bit of time figuring out what could be causing these errors until I read this comment (thanks a lot @Permanente). This really seems to have to do with some reference in the example project that says ../../../../whatever and therefore needs the “HelloCpp” folder (or to whatever you renamed it) to be in an extra folder.

    • Shubhangi

      even I faced same problem …. and resolved by reading this post……Thanks

  21. cocos2d-x環境構築メモ2 » MOKYN

    [...] 最初にこの「イチから構築するチュートリアル」を参考に環境構築してみたのですが、どうもAndroidプロジェクトでエラーが起きたりうまく起動できない場合があったりでしっくりきませんでした。しかし、こっちの「samples/HelloCppをコピーするチュートリアル」を試してみたところ非常にスムーズで分かりやすく環境構築できました。 [...]

    Reply
  22. Just Games

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

    Reply
  23. » #1GAM - dpk's weblog

    [...] I was looking for a framework that was multiplatform and this one fit the bill. I was able to put together a barebones repository that holds all the doodads necessary to launch a game on iOS, Mac, and Android from the same code, based on Cocos2d-X Meta-Project but updated for recent betas. [...]

    Reply
  24. Fernado Javier Fernandez

    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.

    Reply
  25. Carlos

    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

    Reply
    • Nat Weiss

      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.

  26. sts2055

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

    Reply
  27. sts2055

    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?

    Reply
  28. John

    Hi,

    first I’d like to say thanks, I spent a few hours trying to find exactly what you have put together here, and it’s been a great help.
    though, I’m trying to get a starting windows project working and I don’t know what to do about these three errors.

    Error 4 error C1083: Cannot open include file: ‘CCStdC.h’: No such file or directory c:\users\john\desktop\new folder\trunk\projects\cpp\cocoaplatformer\proj.win32\main.h 11 1 CocoaPlatformer

    Error 5 error C1083: Cannot open include file: ‘cocos2d.h’: No such file or directory c:\users\john\desktop\new folder\trunk\projects\cpp\cocoaplatformer\classes\helloworldscene.h 4 1 CocoaPlatformer

    Error 6 error C1083: Cannot open include file: ‘cocos2d.h’: No such file or directory c:\users\john\desktop\new folder\trunk\projects\cpp\cocoaplatformer\classes\appdelegate.h 4 1 CocoaPlatformer

    if you could help asap that would be great, thanks!

    Reply
    • Min

      Looks like you need to setup the directories your compiler will look for header files.

  29. Mazyad Alabduljaleel

    This tutorial is awesome, loved it! Kudos!

    I just really hoped that the Mac and iOS projects were fused together by cocos2d-x group in a single project, with multiple targets, cause now, each time I add a resource or source file to the iOS project, I have to do that to the Mac project as well… Kinda tedious, but not too serious.

    Android on the other hand is awesome, since it runs the build_native.sh script, so by modifying that script, you get an automated way to include all the new source files into the project!

    Check this out for more:
    http://cocos2d-x.org/boards/6/topics/28444

    Reply
  30. jimmy

    hey, I'm  really a fisher on cocos2d-x. I’ ve bought the paralaxer for development.
    As the method metioned in most cocos2dx introduce, I m succesed to runn the hellocpp on my anroid 4.0, But failed on paralaxer, with error msg ‘classnotfound with your.company.your.game.paralax ‘. so I copy the sources into my hellocpp project classes dir, and changed the makefile.Almostly I run the game without an file woosh.wav file not found exception.
    Any recommand is prefered,thanks !

    Reply
    • Nat Weiss

      Which NDK are you using? Try Google’s latest.

      Did you compile with commandline or Eclipse? Try commandline.

  31. Nick

    I’m getting the same errors as john, but I’m not sure what you mean by “Looks like you need to setup the directories your compiler will look for header files.”

    Reply
  32. Adalberto

    A couple of questions:
    I’m running windows. Is there anyway to get my project to update all the different project types at once (Android, iOS, Android) when I build? I realize that once the iOS project is updated, it’ll have to be actually built on a OSX machine.

    2nd: I can get my project to build, and if I run it as a debug thing inside of Visual Studio, it’ll show up. However, the actual exe won’t open. Instead it just processes for a few seconds, then gives up.

    Reply
    • Nat Weiss

      I suppose you could add a custom build step to the Visual Studio solution that runs proj.android/build_native.sh. That would at least build Android and win32 in one step.

      If your exe hangs, try moving all the art files into the same directory as the exe.

  33. NNL

    I see you have a fullscreen option on the mac, that’s great! Do you know how to implement fullscreen for win32? I’d really love to see that added. Can add so much more atmosphere to the game when it’s fullscreen.

    Reply
    • Georgia Nelson

      I have modified CCEGLView to allow for the Win32 fullscreen support. I put details in a Cocos2dx forum thread. I can’t put a URL in here, but if you search “Win32 Fullscreen” or for User 8603 (“Georgia Nelson”) you’ll see my response there.

  34. Jeremy Kimayong

    Is it possible to run cocos-2dx in windows 7? Can somebody help me. :)

    Reply
  35. ashish

    hi i need to converteclipse project to c++ … but when writing the build command i dont know what to write in place of bash i am using cygwin and there is bash_profile… do i hav to give its path followed by bash or bash_profile

    Reply
    • Nat Weiss

      Ashish, from what I can tell, cygwin maps it’s own directory structure. So even though in Windows you don’t technically have a file called c:\bin\bash, in cygwin you can access /bin/bash. You should be able to run scripts with a #!/bin/bash at the top and .bash_profile should work as well.

  36. steve

    Firstly, thank you for such an excellent set of tutorials which has sparked my interest to get back into game coding.

    I followed happily up to running ‘create-multi-platform-projects.py’. I’ve download cocos2d-x-alpha3 but can’t find any trace of this script.

    Does anyone know if this step has changed?

    Reply
    • Nat Weiss

      In the latest 3.0-alpha1 it looks like they moved the script to tools/project-creator/create_project.py. Does this work for you?

      EDIT: Yep, this is the new script. It works exactly as the old one did with the same command line parameters.

Leave a Comment



− 7 = one

Brought to you by the iPhone Game Kit.