Having taken part in numerous game developer events, conferences and port-a-thons, I’ve been asked the following question a lot: Is there a way to bring my cocos2d based iOS game to BlackBerry 10? The answer is simple – absolutely! Use cocos2d-x.
Cocos2d-x is an open-source and cross-platform 2D gaming framework and a direct C++ port of the popular Objective-C based cocos2d framework. Except for the programming language, the two frameworks APIs are very similar. If you have experience with cocos2d framework, it should be a fairly straightforward porting process. Cocos2d-x is also supported on multiple platforms including BlackBerry 10, iOS, and Android. Migrating your game from cocos2d to cocos2d-x opens up your game to bigger audience and monetization opportunities on various application markets with minimal development and maintenance efforts. As an active contributor to the open source gaming community, the Gaming R&D team here at Research In Motion have made sure to provide out-of the-box BlackBerry 10 support for the latest and greatest cocos2d-x library releases.
In this post, I am going walk you through the steps of getting set up with cocos2d-x for game development with the BlackBerry 10 Native SDK.
Get your signing keys!
You need signing keys for device testing and publishing your game to the BlackBerry World. Fill out the form and you will receive the signing keys via email. Make sure to note down the information you filled in the form along with the keys you receive; this may come in handy if you ever lose the signing key password or have issues with the signing process itself.
Set up the BlackBerry 10 Native SDK
Download and install the latest version of the Native SDK from the BlackBerry Developer site. If you do not currently have a device in hand, download our BlackBerry 10 Simulator that can be run with VMWare Player on Windows and Linux or VMWare Fusion on Mac. While you’re at it, be sure to check out our blog post on boosting the simulator performance by 1130%!
Set up the cocos2d-x library
Download the latest cocos2d-x source code from www.cocos2d-x.org and extract it to your workspace location. Since we have already added the BlackBerry 10 project support to it, you can directly import it to the project workspace through following steps:
1. File -> import -> Existing Projects into Workspace -> cocos2dx source directory
2. Import the relevant proj.blackberry eclipse projects. For example, there is no need to select proj.android, project.linux etc.
3. Build the cocos2d-x project
a) Select the imported folders, then right-click and choose the appropriate Build Configuration. For simulator development, choose appropriate simulator build configurations. For device development, choose the appropriate device build configurations; for example, Device-Debug for testing/debugging and Device-Release for release.
b) Select the imported folders. Right click and Build.
Note: On the recent cocos2dx build cocos2d-2.0-x-2.0.4 you may see this:
undefined reference symbol ‘FT_New_Face’ undefined error.
This is because the freetype library is missing in the project dependencies — let’s see how to fix that:
1. Right click the erroneous project
2. Select Properties -> C/C++ General -> Paths and Symbols
3. Select [All Configurations] from the configuration dropdown menu
4. Choose Libraries tab and Add freetype library
5. Build again.
Rest assured, the fix is coming
Running a cocos2dx Sample
The imported project comes with a sample template project called BBTemplateProject. Let’s try and deploy it onto a simulator first and then a BlackBerry 10 device.
1. Make sure the Simulator/Device Development mode is turned on
2. Check Settings->Security and Privacy-> Development mode
(Note: On a device, you may be asked to set a password the first time.)
3. If no Device or Simulator targets are defined, Add a new target
4. Right-click project
a) Use Run-as BlackBerry C++ Application for deploy and launch the application.
b) Use Debug-as BlackBerry C++ Application for deploy and debug the application.
5. If you have never set up the signing keys and you are trying to run the game on a device for the first time, a BlackBerry Deployment Setup Wizard will pop up that helps you register the signing keys and create debug tokens for on device testing and debugging.
If you made it through to this state, you are now officially ready for the fun part of this project: porting your cocos2d code to cocos2d-x code.
Releasing the game
Fast-forward 24 hours; with the help of lots of caffeine and energy drinks, you have done it! Now you want to publish your game to the BlackBerry World. First, you need to become a BlackBerry vendor to be able to publish game in BlackBerry World. Once approved, you have to build a release version of the game that can be published, and here is how you do it:
1. Change the Build Configurations of the Game project and its dependent libraries to Device-Release and Build
2. Sign and export the project: File -> export -> BlackBerry -> release build
3. Test and publish the release version of the game through the vendor portal.