多个屏幕上的 VolatileImage JFrame
我有一个 JFrame,其中使用 Graphics2D 使用 this 教程。我主要复制了代码来看看它是如何工作的,但为我的游戏稍微编辑了它。我正在运行带有两个屏幕的计算机。
当我将游戏窗口拖到最初没有出现该窗口的另一个屏幕上时,就会出现问题。窗口变成灰色,屏幕上没有显示任何图形,即使是我用 Graphics2D 绘制的简单矩形也是如此。仅当我调用 易失性图像的绘制方法时才会发生这种情况,如教程中所示。
我相信这可能与此有关……
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
但我不确定。
任何帮助将不胜感激。了解 VolatileImage 是否是我的游戏应该采用的方式,或者 BufferedImage 或其他东西是否是性能和帧速率更好的方法,这也很有趣。
I have a JFrame in which I am using Graphics2D to draw a VolatileImage using this tutorial. I have mainly copied the code to see how it works, but have slightly edited it for my game. I am running my computer with two screens.
The problem arises when I drag the window of the game onto the other screen which the window did not originally appear on. The window goes grey and no graphics are shown on screen, even the simple rectangles I have drawn with the Graphics2D. This only happens when I call for the draw method of the volatileimage as shown in the tutorial.
I believe it may have something to do with this...
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
...but I am not sure.
Any help would be greatly appreciated. It would also be interesting to know if VolatileImage is the way I should be going for my game or if BufferedImage or something else is a better method for performance and frame rate.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,你是对的。
VolatileImage
是特定于设备的。从“VolatileImage API 用户指南” 中您可以阅读:和
将框架拖动到另一个屏幕设备时,您需要检查
VolatileImage.validate(gc)
方法并重新创建图像到新设备。请注意,有些情况下您无法创建VolatileImage
,在这些情况下您需要依靠另一个Image
实现,例如BufferedImage
。Yes, you are correct.
VolatileImage
is device-specific. From "The VolatileImage API User Guide" you can read:and
When dragging your frame to another screen device you need to check the result from the
VolatileImage.validate(gc)
method of your and recreate the image to the new device. Note that there are cases when you cannot create aVolatileImage
, in those cases you need to fall back on anotherImage
implementation likeBufferedImage
.