码迷,mamicode.com
首页 > Web开发 > 详细

OC和Cocos-js的互相调用

时间:2018-07-27 20:56:52      阅读:639      评论:0      收藏:0      [点我收藏+]

标签:number   color   nsstring   class   cal   string   sea   record   cname   

OC调用cocos-js

#import "ScriptingCore.h"
#import "cocos2d.h"
#include "scripting/js-bindings/manual/ScriptingCore.h"
#include "scripting/js-bindings/manual/jsb_conversions.hpp"
#include "scripting/js-bindings/jswrapper/SeApi.h"
#define JSCallBackHasVoice @"cc.director.getScene().getChildByName(‘Canvas‘).getComponent(‘OCRecorder‘).hasVoice"
//hasVoice是cocos-js的方法
+ (void)JsCallBack:(NSString *)funcNameStr WithIndex:(NSInteger)index{
    std::string funcName = [funcNameStr UTF8String];
    NSString *numberStr  = [NSString stringWithFormat:@"%ld",index];
    std::string coins = [numberStr UTF8String];
    std::string jsCallStr = cocos2d::StringUtils::format("%s(\"%s\");",funcName.c_str(), coins.c_str());
    se::ScriptEngine::getInstance()->evalString(jsCallStr.c_str());
}

 

OC和Cocos-js的互相调用

标签:number   color   nsstring   class   cal   string   sea   record   cname   

原文地址:https://www.cnblogs.com/wycstudy/p/9379240.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!