android - 如何从android后端调用核心方法?

标签 android libgdx

我可以使用来自 GDX(平台特定代码)的 android 方法,但是是否可以从 android 后端获取 libgdx 方法? 我有火力数据库。在我游戏的安卓端,我捕捉到数据库中的任何变化。我需要将更改转移到我的核心后端(例如更新一些 Actor 、标签等)。最好的方法是什么?

最佳答案

使用Interfacing 可以访问核心模块 内的平台特定API .


core-module 是所有平台的通用部分,因此您可以在项目的任何地方访问。

保留ApplicationListener的引用,如果你想调用你的核心的任何方法/访问数据成员模块。

在android模块内部:

public class AndroidLauncher extends AndroidApplication {

    MyGdxGame gdxGame;

    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();

        gdxGame=new MyGdxGame();
        initialize(gdxGame, config);
    }

     public void andoridMethod(){
         System.out.println(gdxGame.x);      //access data member
         gdxGame.doSomething();              //access method
     }
}

内部核心模块:

public class MyGdxGame implements ApplicationListener {

      public int x=4;

      public void doSomething(){}

      // Life cycle methods of ApplicationListener
}

关于android - 如何从android后端调用核心方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51431656/

相关文章:

java - 二维数组到 int(种子)并返回

java - 千个 Sprite 绘制效果不佳

android - setClickable() 被 onClickListener 阻挠

android - 覆盖操作栏中的向上按钮

java - LibGDX实现可滚动的HexMap

java - PolygonShape 用 "area > 1.19209289550781250000e-7F"断言

opengl-es - 在 OpenGL ES 中指定清晰颜色的目的是什么?

android - 在 Android 应用程序中自定义 Facebook 登录按钮

android - 设备电池电量不足时,android 策略是什么?

android - setDither、setFilterBitmap 和 setAntiAlias 在 Canvas 中的作用是什么?