且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 LibGDX 中添加多个窗口?

更新时间:2023-11-18 21:38:16

基本上可以在单独的进程中运行每个窗口(使用答案这里 看看如何实现 JavaProcess,下面使用):

Basically, you can run each window in a separate process (use the answer here to see how to implement JavaProcess which is used below):

public class Tiles {
   public static void main(String[] args) {
      LwjglApplicationConfiguration configForTiles = new LwjglApplicationConfiguration();
      TilePresets tilesWindow = new TilePresets();
      LwjglApplication tiles = new LwjglApplication(tilesWindow, configForTiles);
   }
}

Wrapper.java 是主要入口点.这是启动两个窗口的地方:

Wrapper.java is the main entry point. It's where launching both windows occurs:

public class Wrapper {
   public static void main(String[] args) {
      // Launch mapWindow regularly 
      LwjglApplicationConfiguration configForMap = new LwjglApplicationConfiguration();
      MapMaker mapWindow = new MapMaker();
      LwjglApplication map = new LwjglApplication(mapWindow, configForMap);

      try {
         int res = JavaProcess.exec(Tiles.class); // Where the second window is shown
      } catch (IOException e) {
         e.printStackTrace();
      } catch (InterruptedException e) {
         e.printStackTrace();
      }
   }
}

信用提醒!我有一个类似的问题,我在某个地方找到了这个解决方案,但我不记得在哪里.找到后我会在这里发布源代码.

Credit alert! I had a similar question and I found this solution somewhere, but I can't remember where. I'll post the source here when I find it.

编辑:感谢我提出这个想法的人解决方案.

Edit: Credit goes to the person from which I got the idea for this solution.