我可以使用来自 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/