嵌入式cocos2d-js应用程序可以调用c ++吗? [英] Can an embedded cocos2d-js app call back out to c++?
问题描述
我正在研究通过将cocos2d-js嵌入为现有iOS应用程序中的视图的可能性.为了使这项工作有效,我将需要cocos2d与周围应用程序之间的双向通讯.
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.
经过初步调查,我确定可以使用 ScriptingCore
调用 in 到cocos:
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);
那么,我的问题是做相反的事情.是否可以(例如响应用户输入)将cocos2d-js回调到C ++?理想情况下,将存在一种向 ScriptingCore
注册回调的方法,该方法可以从JavaScript调用.
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.
推荐答案
我相信可以做到,但是我还没有尝试过,也找不到一个简单明了的例子.我所能做的就是将您指向 git页面,这显然可以在C ++和JS代码之间进行双向通信.
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.
这篇关于嵌入式cocos2d-js应用程序可以调用c ++吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!