Cocos2D-X Tutorial for iOS and Android: Getting Started
In this Cocos2D-X tutorial, you’ll learn how to use Cocos2D-X and C++ to produce a cross-platform “Hello World” app that will run under both iOS and Android. By .
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
Cocos2D-X Tutorial for iOS and Android: Getting Started
30 mins
- Hello, Cocos2D-X for iOS!
- Setting up Eclipse for Cocos2D-X Development
- Setup the Android NDK (Native Development Toolkit)
- Hello, Cocos2D-X for Android!
- Building the Project
- Defining a Combined Java/C++ Project in Eclipse
- What About the Java Code?
- Combining the iOS and Android Project Structures
- When to Use Xcode, and When to Use Eclipse?
- Debugging Tips and Tricks
- Where To Go From Here?
Debugging Tips and Tricks
Debugging the iOS part of the Cocos2d-x project is exactly the same as debugging standard Cocos2D code, so there is nothing special to add here.
However, for Android, here’s some notes.
When building for debug with NDK, a ‘server side’ gdb and gdbcontext is bundled inside the APK generated by the ndk-build shell and populated to the device. This remote debugger will communicate with any compatible GDB client agent.
The best GDB agent to use with Eclipse is the NVidia debug manager plugin, but installing that is beyond the scope of this Cocos2D-X tutorial.
Note:
If you want to install the NVidia Debug Manager plugin, all you really need to do is to go to this page and download the full Tegra Android Developer Pack even though you might think you don’t need it. When you install the Tegra Developer pack, it gives you the option to select what you want to install and at this point, you can opt to install just the plugin.
However, that will not install the plugin into Eclipse. It will simply put the plugin ZIP file on your hard drive. Now follow the instructions on this PDF to actually install the plugin.
Note:
If you want to install the NVidia Debug Manager plugin, all you really need to do is to go to this page and download the full Tegra Android Developer Pack even though you might think you don’t need it. When you install the Tegra Developer pack, it gives you the option to select what you want to install and at this point, you can opt to install just the plugin.
However, that will not install the plugin into Eclipse. It will simply put the plugin ZIP file on your hard drive. Now follow the instructions on this PDF to actually install the plugin.
I found that on some physical devices (Samsumg Galaxy S being one of them), the remote debugger always fails to start though it correctly starts with the same APK on an AVD (Android Virtual Device).
To start a debug session select your project, right click and select Debug As/Android NDK Application, as you can see below:
Do note though that you get the Android NDK Application option only if you download and install the NVidia debug manager plugin. Otherwise, you will not see the above option when you right-click.
You can set a breakpoint by double clicking a code line, as you can see here:
When the breakpoint hits, it will halt at that line of code with more information:
Sadly, debugging from Android using GDB may not always work, so you might find it helpful to add an extra debug tracing system in place as an alternative debugging method. For more info on this, contact me and I’ll share some tips on how you might do this.
Where To Go From Here?
Congrats, you now have your hands dirty with Cocos2D-X and have your iPhone and Android development environments fully set up and ready to go!
Stay tuned for my next Cocos2D-X tutorial, where I’ll show you how you can make a complete cross-platform Space Game with Cocos2D-X.
In the meantime, if you have any questions or comments about this Cocos2D-X tutorial or Cocos2D-X in general, please join the forum discussion below!