Hi everyone,
I was working for several weeks on making a game for iOS with Javascript for my company.
The challenge was to use native components from the Javascript, like Facebook and GameCenter.
I made it and created Khalou, a reflection board game.
The most difficult part was to create bindings.
I made a double wrapper: Javascript calls C++, that calls Objective-C.
I would like to share my work, hoping this will help other people and contributors to Cocos2d-x.
The goal of my game is to make a completely white board by flipping stones following 2 types of moves.
I can’t give you any download link, but I took as many screens as I can.
The splashScreen:
http://image.noelshack.com/fichiers/2012/52/1356540674-capture-d-ecran-2012-12-26-a-17-33-07.png
The menu:
http://image.noelshack.com/fichiers/2012/52/1356540670-capture-d-ecran-2012-12-26-a-17-31-48.png
Connected to the GameCenter:
http://image.noelshack.com/fichiers/2012/52/1356540675-capture-d-ecran-2012-12-26-a-17-33-35.png
Leaderboard:
http://image.noelshack.com/fichiers/2012/52/1356540683-capture-d-ecran-2012-12-26-a-17-34-39.png
A game:
http://image.noelshack.com/fichiers/2012/52/1356540685-capture-d-ecran-2012-12-26-a-17-34-47.png
EndGame:
http://image.noelshack.com/fichiers/2012/52/1356540679-capture-d-ecran-2012-12-26-a-17-36-22.png
EndGame with iAd integration:
http://image.noelshack.com/fichiers/2012/52/1356540684-capture-d-ecran-2012-12-26-a-17-36-49.png
Sharing with Facebook:
http://image.noelshack.com/fichiers/2012/52/1356540685-capture-d-ecran-2012-12-26-a-17-38-03.png
So far, it’s impossible to call native functions without creating bindings, so I’ll tell you my procedure.
You can also first look at the github that I used to help me
https://github.com/funkaster/cxx-generatorblobmaster/README.md
I made a singleton for facebook in Obj-C, here is facebook_objc.h:
@interface FacebookHelper_objc : NSObject
{
}
@property (strong, nonatomic) NSMutableDictionary *postParams;
@property (nonatomic, retain) Facebook *facebook;
- (BOOL) publishScore:(int) score;
+ (FacebookHelper_objc*) sharedFacebookHelper;
@end
So, when I want to call publishScore, I do
[[FacebookHelper_objc sharedFacebookHelper] publishScore:score];
I put this in a static function of a C*+ class, inside the facebook.mm file :
<pre>
#include “facebook.h”
bool FacebookHelper::publishScore
{
return publishScore:score];
}
</pre>
and create the class, here the header facebook.h:
<pre>
#include “facebook_objc.h”
class FacebookHelper
{
public:
static bool publishScore;
};
</pre>
Don’t forget to put your methods public.
Next, I created the bindings. I used the cxx-generator joined in the tools, and used the generator.py, with the file BindingsHelper.ini
You need to tell to the script the paths to the different header directories through this file.
It was certainly the most painful part of my project, because I used the OSX C*+ library, that uses sometimes other keywords, like OGL for openGL and so…
After satisfying all the header required for the binding generation, I put all the generated files (facebook_bindings.cpp, facebook_bindings.hpp, facebook_bindingsapi.js) into my project.
In fact, It has a lot more difficult and long to make bindings for me, because of dependences of the bindings generator.
I would make soon a public github project with that game, but I can’t yet… 
I want to share my great (and creepy) code to you, because that’s the most interesting.
edit:
Sorry, but the second (the bigger) *.ini file joined in this post is the good one, and I don’t know how to delete old files.
userconf.ini.zip (0.3 KB)
BindingsHelper.ini.zip (0.8 KB)