Work with external libraries/SDK?

Hi, is there a way to integrate external libraries/SDK to Cocos Creator games? I want to build a prototype of asynchronous multiplayer turn based game with webSockets. Any tips?
Thanks!

That depends,

For web games, you can use npm modules, or require any third party libs with node.js require, as long as your third party lib uses pure JavaScript / DOM APIs (Node.js API, like fs, won’t be available on web)

For native games, DOM APIs won’t be available, so you can only use pure JavaScript libs. If you want to use native libs (C++ / Java / OC), you can build your project for targeted platform with default template in build panel, then embed the native library in your built native project (located in the build path).

1 Like

then, how do I call C++/Java/OC methods from game scripts?

You can use JNI to call Java Static methods - read this:
http://www.cocos2d-x.org/wiki/Invoking_Android_Java_methods_from_JavaScript
for Obj-C - read this:
http://www.cocos2d-x.org/wiki/Invoking_Objective-C_methods_from_JavaScript
then you can call C++ methods from Java (I don’t know if in Obj-C it works too - I’m working in Android)

Hope it helps.

1 Like