Java 2D 绘图优化性能 [英] Java 2D Drawing Optimal Performance

查看:41
本文介绍了Java 2D 绘图优化性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写 Java 2D 游戏.我正在使用内置的 Java 2D 绘图库,在我从 JFrame 中的 Canvas(有时是全屏的)的 BufferStrategy 中获取的 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 性能问题

它显示了性能下降的原因以及如何修复它.但不能保证在所有平台上都能正常工作.你会在帖子中看到原因.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆