zoukankan      html  css  js  c++  java
  • Java调用JavaScript

    使用cocos2d-js开发游戏时常常需要和native平台交互,Java回调JavaScript也是常常使用的功能,贴心的cocos都已经帮我们准备好了,直接使用即可!
    在你的项目中包含Cocos2dxJavascriptJavaBridge,这个类有一个evalString方法可以执行js代码,它位于frameworksjs-bindingsindingsmanualplatformandroidjavasrcorgcocos2dxlib文件夹下。
    Java:

     public void onTest() {
            //一定要在GL线程中执行
            app.runOnGLThread(new Runnable() {
                @Override
                public void run() {
                    Cocos2dxJavascriptJavaBridge.evalString("UtilsPlatform.test("Javascript Java bridge!")");
               }
          });
     }

    JavaScript:

    var UtilsPlatform = {};
    UtilsPlatform.test = function (t) { cc.log(t); };
    
  • 相关阅读:
    POJ 2136
    POJ 2121
    POJ 2127
    POJ 2126
    POJ 2109
    POJ 2105
    POJ 2101
    POJ 2075
    Uboot — 配置过程
    Uboot — 编译体验
  • 原文地址:https://www.cnblogs.com/skyxu123/p/9543799.html
Copyright © 2011-2022 走看看