Game logic in Java and Cocos2d code using JNI



I was wondering, would it be possible to write my game logic in Java and use the Jni wrappers to handle the Cocos2d stuff?

I haven’t seen any articles on people writing their game logic in Java and just using the C++ code for the rendering. So I’m wondering if anyone else has tried that?

In theory I think it would work, as it’s pretty similar to what the Libgdx folks are doing, but I’m not totally sure.


It is possible but I would suggest that in the end, you’d be happier with a C*+ solution.
I say this having implemented four successful Android / Java games — I have been so happy with the results on Cocos2d-x I’ve moved to 100% C*+.

For your original question, here is my initial reaction …

  1. Good game logic will require solid object models, which will be cumbersome to pass into and out of JNI

  2. If you are implementing a real time or semi-real time game you may need the rendering / updating thread to talk to the game logic a lot — this may be an issue because of the overhead you’ll find JNIEnv* construction has

  3. If you are rendering in Cocos2d-x you’re using CCNode and it’s children … those are AWESOME classes for building interactive game UI … what is Java going to give you … really?

  4. The entire point of Cocos2d-x is to escape the horrible Dalvik JVM and it’s pathetic garbage collection scheme and be cross platform. Using JNI defeats the purpose.

  5. If you REALLY want to write you game logic for cross platform games in Java — use LibGDX, not cocos2d-x — you’ll be happier if you really have to have Java — and you’ll stay mostly cross-platform.