本文介绍了在LibGDX中添加多个窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想从我的DekstopLauncher.java创建多个游戏窗口。 第二个应该能够与第一个交互,例如要求一个字符串。 是否可以这样做?这是我在DeskopLauncher类中尝试的: 这是创建第一个窗口的过程: LwjglApplicationConfiguration configForTiles = new LwjglApplicationConfiguration(); TilePresets tilesWindow = new TilePresets(); LwjglApplication tiles = new LwjglApplication(tilesWindow,configForTiles); 而这第二个 LwjglApplicationConfiguration configForMap = new LwjglApplicationConfiguration(); MapMaker mapWindow = new MapMaker(); LwjglApplication map = new LwjglApplication(mapWindow,configForMap); 仅创建一个作品。但是,如果添加它,它给了我这个错误: LwjglApplication:无法初始化音频,禁用音频 java。 lang.IllegalStateException:任何时候都只能实例化一个OpenAL上下文。 在org.lwjgl.openal.AL.create(AL.java:113)在org.lwjgl.openal.AL.create(AL.java:102)在org.lwjgl .openal.AL.create(AL.java:206) at com.badlogic.gdx.backends.lwjgl.audio.OpenALAudio。(OpenALAudio.java:72) at com.badlogic.gdx。 backends.lwjgl.LwjglApplication。(LwjglApplication.java:83) at com.badlogic.gdx.backends.lwjgl.LwjglApplication。(LwjglApplication.java:64) at com.whoplays.mapmaker.desktop。 DesktopLauncher.main(DesktopLauncher.java:16)在线程LWJGL Application中的异常java.lang.IllegalStateException:从线程Thread [LWJGL Application,5,main]:线程[LWJGL Application,5,main]已经具有org.lwjgl.opengl.ContextGL.checkAccess(ContextGL.java:184)在org.lwjgl.opengl.ContextGL.forceDestroy(ContextGL.java:241)在org.lwjgl。 opengl.DrawableGL.destroy(DrawableGL.java:130) at org.lwjgl.opengl.Display $ 5.destroy(Display.java:834) at org.lwjgl.opengl.Display.destroy(Display .java:1095) at com.badlogi c.gdx.backends.lwjgl.LwjglGraphics.createDisplayPixelFormat(LwjglGraphics.java:197) at com.badlogic.gdx.backends.lwjgl.LwjglGraphics.setupDisplay(LwjglGraphics.java:174) at com。 badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:138) at com.badlogic.gdx.backends.lwjgl.LwjglApplication $ 1.run(LwjglApplication.java:120) href =https://stackoverflow.com/a/723914/2016436>这里了解如何实现下面使用的 JavaProcess ): p> 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 code>是主要的入口点。这就是启动这两个窗口的地方: public class Wrapper { public static void main(String [] args){ //定期启动mapWindow LwjglApplicationConfiguration configForMap = new LwjglApplicationConfiguration(); MapMaker mapWindow = new MapMaker(); LwjglApplication map = new LwjglApplication(mapWindow,configForMap); 尝试{ int res = JavaProcess.exec(Tiles.class); //第二个窗口显示} catch(IOException e){ e.printStackTrace(); } catch(InterruptedException e){ e.printStackTrace(); } } } 我有类似的问题,我发现这个解决方案的地方,但我不记得在哪里。当我找到它时,我会在这里发布源代码。 编辑:信用关系到我从中获得此信息的人解决方案。 I want to create multiple game windows from my DekstopLauncher.java .The second one should be able to interact with the first one, for example asking for a string.Is it possible to do so? And how?This is what I tried in the DeskopLauncher class:This is creating the first window: LwjglApplicationConfiguration configForTiles = new LwjglApplicationConfiguration();TilePresets tilesWindow = new TilePresets();LwjglApplication tiles = new LwjglApplication(tilesWindow, configForTiles);And this the second LwjglApplicationConfiguration configForMap = new LwjglApplicationConfiguration();MapMaker mapWindow = new MapMaker();LwjglApplication map = new LwjglApplication(mapWindow, configForMap);Creating only one works. But if add both it gives me this error: LwjglApplication: Couldn't initialize audio, disabling audiojava.lang.IllegalStateException: Only one OpenAL context may be instantiated at any one time.at org.lwjgl.openal.AL.create(AL.java:113)at org.lwjgl.openal.AL.create(AL.java:102)at org.lwjgl.openal.AL.create(AL.java:206)at com.badlogic.gdx.backends.lwjgl.audio.OpenALAudio.(OpenALAudio.java:72)at com.badlogic.gdx.backends.lwjgl.LwjglApplication.(LwjglApplication.java:83)at com.badlogic.gdx.backends.lwjgl.LwjglApplication.(LwjglApplication.java:64)at com.whoplays.mapmaker.desktop.DesktopLauncher.main(DesktopLauncher.java:16)Exception in thread "LWJGL Application" java.lang.IllegalStateException: From thread Thread[LWJGL Application,5,main]: Thread[LWJGL Application,5,main] already has the context current at org.lwjgl.opengl.ContextGL.checkAccess(ContextGL.java:184)at org.lwjgl.opengl.ContextGL.forceDestroy(ContextGL.java:241)at org.lwjgl.opengl.DrawableGL.destroy(DrawableGL.java:130)at org.lwjgl.opengl.Display$5.destroy(Display.java:834)at org.lwjgl.opengl.Display.destroy(Display.java:1095)at com.badlogic.gdx.backends.lwjgl.LwjglGraphics.createDisplayPixelFormat(LwjglGraphics.java:197)at com.badlogic.gdx.backends.lwjgl.LwjglGraphics.setupDisplay(LwjglGraphics.java:174)at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:138)at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120) 解决方案 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 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. 这篇关于在LibGDX中添加多个窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 06-15 22:46