Search code examples
androidioscocos2d-x

Interact with Cocos2d-x Scene at android / ios native window


I'd like to know if Its possible to interact with Cocos2d-x Scene?

Like if I press the button, I can call a method inside Cocos2d-x, for example to start an animation.

If yes, please provide me a sample.

enter image description here


Solution

  • Yes, it's possible. So on iOS: it's very simple, you just need to import the C++ header file in your objective c(mm file) and call. You might need to save the instance somewhere. This still applies to cocos2d-x - Calling C++ method from Objective C

    Android: You need to define JNI function on C++ side and call from java. Please refer this link : http://stnguyen.com/cocos2d-x/call-cpp-functions-from-java.html