Java 2D绘图的最佳性能 [英] Java 2D Drawing Optimal Performance
问题描述
我正在编写一个Java 2D游戏。我正在使用内置的Java 2D绘图库,使用从JFrame中的Canvas获取的Graphics2D(有时会进行全屏筛选)。 BufferStrategy是双缓冲的。通过定时器主动完成重绘。我有一些性能问题,特别是在Linux上。
I'm in the process of writing a Java 2D game. I'm using the built-in Java 2D drawing libraries, drawing on a Graphics2D I acquire from a BufferStrategy from a Canvas in a JFrame (which is sometimes full-screened). The BufferStrategy is double-buffered. Repainting is done actively, via a timer. I'm having some performance issues though, especially on Linux.
Java2D有很多创建图形缓冲区和绘图图形的方法,我只是不知道我正在做正确的事情。我一直在尝试使用graphics2d.getDeviceConfiguration()。createCompatibleVolatileImage,这看起来很有前景,但我没有真正的证据证明,如果我将绘图代码切换到该图形,速度会更快。
And Java2D has so very many ways of creating graphics buffers and drawing graphics that I just don't know if I'm doing the right thing. I've been experimenting with graphics2d.getDeviceConfiguration().createCompatibleVolatileImage, which looks promising, but I have no real proof it it's going to be any faster if I switch the drawing code to that.
根据您的经验,在Java 1.5+中将2D图形渲染到屏幕上的最快方式是什么?请注意,这个游戏还有很长的路要走,所以我不想切换到完全不同的绘图方法,如OpenGL或游戏引擎。我基本上想知道如何获得使用Graphics2D对象在屏幕上绘制东西的最快方式。
In your experience, what is the fastest way to render 2D graphics onto the screen in Java 1.5+? Note that the game is quite far ahead, so I don't want to switch to a completely different method of drawing, like OpenGL or a game engine. I basically want to know how to get the fastest way of using a Graphics2D object to draw stuff to the screen.
推荐答案
我觉得你有同样的问题。看看我的帖子:
I'm having the same issues as you are I think. Check out my post here:
Java2D Performance Issues
它显示了性能下降的原因以及如何解决这个问题。但不能保证在所有平台上都能正常工作。你会在帖子中看到为什么。
It shows the reason for the performance degradation and how to fix it. It's not guaranteed to work well on all platforms though. You'll see why in the post.
这篇关于Java 2D绘图的最佳性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!