cocos2d js 对android和ios混编记录

前端之家收集整理的这篇文章主要介绍了cocos2d js 对android和ios混编记录前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1、oc调用cocos2d js

NSMutableString * nsmString = [NSMutableString string];
[nsmString appendString: @"g_WeiXinLogin("];
[nsmString appendFormat:@"\"%@\"",openid];
[nsmString appendFormat:@",\"%@\"",token];
[nsmString appendFormat:@",isbind];
[nsmString appendString: @")"];

NSString *funString = [NSString stringWithString:nsmString];

NSLog(@"===== funString:%@",funString);

const char * funchar = [funString UTF8String];
//oc调用js
ScriptingCore * sc = ScriptingCore::getInstance();
jsval outVal;
sc->evalString(funchar,&outVal);


2、cocos2d js 调用oc

var ret = jsb.reflection.callStaticMethod("NativeOcClass",
"callNativeUIWithTitle:andContent:",
"cocos2d-js",
"Yes! you call a Native UI from Reflection")
;

3、cocos2d js 调用android

jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Test","hello","(Ljava/lang/String;)V","this is a message from js");

4、android调用 cocos2d js

Cocos2dxJavascriptJavaBridge.evalString("g_SmsAutoWrite(\""+smsCode+"\")");



参考网站:官网http://www.cocos2dx.net/post/254

原文链接:https://www.f2er.com/cocos2dx/340645.html

猜你在找的Cocos2d-x相关文章