如果你以你問的方式因此,您將無法維護多平臺功能。這也意味着你將無法在桌面上進行測試。這會花費您很多時間在設備上編譯和加載Android APK。
但是,您應該可以將android
塊中的所有內容剪切並粘貼到項目的build.gradle
文件中的core
塊中。它看起來像這樣:
project(":core") {
apply plugin: "java"
apply plugin: "android"
configurations { natives }
dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
}
}
但就像我說的,這可能不是你想要做的。我建議使用一個接口,以便處理TaskSets的所有代碼都保留在Android模塊中。事情是這樣的:
public interface PlatformResolver {
public void handleTasks();
}
-
public class MyGame extends ApplicationAdapter {
//......
PlatformResolver platformResolver;
public MyGame (PlatformResolver platformResolver){
this.platformResolver = platformResolver;
}
//.....
public void render(){
//...
if (shouldHandleTasks) platformResolver.handleTasks();
//...
}
-
public class AndroidLauncher extends AndroidApplication implements PlatformResolver {
public void handleTasks(){
//Do stuff with TaskSets
}
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
someDataType SomeData;
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
// config stuff
initialize(new MyGame(this), config);
}
}
-
public class DesktopLauncher implements PlatformResolver{
public void handleTasks(){
Gdx.app.log("Desktop", "Would handle tasks now.");
}
public static void main (String[] arg) {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.title = "My GDX Game";
config.width = 480;
config.height = 800;
new LwjglApplication(new MyGame(this), config);
}
}
感謝。我很欣賞 –