Can an embedded cocos2d-js app call back out to c++?

泪湿孤枕 提交于 2019-12-10 17:32:25

问题


I'm researching the possibility of using cocos2d-js by embedding it as a view inside an existing iOS app. In order to make this work, I'm going to need 2-way communication between cocos2d and the surrounding application.

After some initial investigation, I have determined that it is possible to call in to cocos using ScriptingCore:

ScriptingCore* sc = ScriptingCore::getInstance();
jsval outVal;
sc->evalString("function()", &outVal);

My question, then, is around doing the reverse. It is possible to (e.g. in response to user input) call back out of cocos2d-js to C++? Ideally, there would be a way to register a callback with ScriptingCore which could be invoked from JavaScript.


回答1:


I believe it can be done, but I have not tried myself, nor can I find a good and concise example. All I can do is point you at SuperSuraccoon's Bluetooth example and it's git page, which apparently does both ways communication between C++ and JS code.



来源:https://stackoverflow.com/questions/24006441/can-an-embedded-cocos2d-js-app-call-back-out-to-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!