问题描述
我正在开发一个 libGDX(LWJGL 之上的库)游戏项目,并从几个不同的工作站使用 Intellij IDEA IDE:
I'm working on a libGDX (library on top of LWJGL) game project, and use the Intellij IDEA IDE from several different workstations:
- 配备两个显示屏(1920x1080 和 1600x1200)的 Windows 7 x64 笔记本电脑,nVidia GT540M.
- Ubuntu 12.04 LTS,配备单显示器 (1366x768)、英特尔集成显卡的笔记本电脑.
- Ubuntu 12.04 LTS 在带有两个显示器(1920x1080 和 1280x1024)的桌面上,nVidia GTS 450.
我在 Ubuntu 机器上使用 OpenJDK for Java 6,在 Windows 机器上使用 Sun/Oracle Java 6(我听说 Java 6 是为了与 Android 兼容而使用的).
I'm using the OpenJDK for Java 6 on the Ubuntu boxes, and Sun/Oracle Java 6 on the Windows box (I heard Java 6 was the one to use for Android compatibility).
全屏运行时:
- Windows 7 笔记本电脑:运行良好.
- Ubuntu 笔记本电脑:工作正常.
- Ubuntu 桌面:背景图片放大显示,只有一部分适合屏幕.+
进一步研究,我看到对 Gdx.graphics.getHeight() 和 Gdx.graphics.getWidth() 的调用返回了覆盖两个显示器所需的矩形大小,在我的例子中是 3200x1080,但是当我告诉我的游戏要全屏运行,它只使用其中一个显示器,所以相机设置为 1920x1080,但我的相机移动和平铺地图平移认为他们有 3200x1080 可以使用,这使得事情扭曲和无法使用(因为角色可以从屏幕向右走).
Looking into this further, I see that the calls to Gdx.graphics.getHeight() and Gdx.graphics.getWidth() return the size of the rectangle needed to cover both displays, in my case 3200x1080, but when I tell my game to run full-screen, it only uses one of the displays, so the cameras get set to 1920x1080, but my camera movement and Tiled map panning think they've got 3200x1080 to work with, making things distorted and unusable (since character can walk off of the screen to the right).
我猜我的问题实际上来自 awt.Toolkit 的 getScreenSize() 调用返回的尺寸,但我不知道如何更深入地询问它以获取它实际使用的屏幕尺寸去全屏.
I'm guessing my problem actually comes from the sizes returned by the awt.Toolkit's getScreenSize() call, but I don't know how to interrogate it more deeply to get the size of the screen it will actually use when I go fullscreen.
我的 DesktopStarter 获取屏幕大小并设置全屏如下:
My DesktopStarter gets the screen size and sets fullscreen as follows:
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
cfg.width = screenDimension.width;
cfg.height = screenDimension.height;
cfg.fullscreen = true;
new LwjglApplication(new Game1(), cfg);
是否有解决方法来获得全屏"实际启动的显示器的高度/宽度?
Is there a work-around to get the height/width of just the display that "full screen" will actually launch into?
所以我看到的问题是执行 game.jar 文件,退出游戏,然后再次重复执行,导致 Gdx.graphics.getDisplayModes 返回的模式列表中显示不同的显示模式() -- 作为 PT下面指出,这是 LWJGL 的 Display.getAvailableDisplayModes()
的薄包装.为什么会这样?为什么在 Ubuntu 的后续运行中会出现一组不同的模式?
So the trouble I'm seeing, is that executing the game.jar file, exiting the game, then executing again, repeatedly, results in different display modes showing up in the list of modes returned by Gdx.graphics.getDisplayModes() -- as P.T. pointed out below, this is a thin wrapper around LWJGL's Display.getAvailableDisplayModes()
. Why is this happening? Why would it be a different set of modes presented on subsequent runs on Ubuntu?
根据 P.T. 的建议,将 LWJGL 引用置于问题之中,因为提供显示模式列表的似乎是 LWJGL.
edit: per P.T.'s suggestion, put LWJGL references in question, since it seems to be LWJGL that's providing the list of display modes.
谢谢!
推荐答案
GraphicsDevice monitors[]=GraphicsEnvironment.getScreenDevices();
Dimension screen_resolution[monitors.length];
for (int monitorID = 0; monitorID < monitors.length; monitorID++)
{
screen_resolution[monitorID] = new Dimension(monitors[monitorID].getDisplyMode().getWidth(),monitors[monitorID].getDisplyMode().getHeight());
}
这篇关于java 和 libGDX/LWJGL 游戏全屏尺寸错误,适用于 Ubuntu 上的多个显示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!