我如何加快这一挥杆动画? [英] How do I speed up this swing animation?

查看:124
本文介绍了我如何加快这一挥杆动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我绘制动画到挥杆的JPanel。在1024×1024的屏幕被划分为2000张覆盖的屏幕完全相同(无重叠)。

I am drawing an animation onto a swing JPanel. The 1024x1024 screen is divided up into 2000 pieces which cover the screen exactly (no overlap).

每件是一个非常小的一块屏幕(它的1 / 2000'th)的。动画绘制一块每毫秒的缓冲图像在改变像素和调用reaint()。因此,在整个屏幕每2秒改变。动画是在java.util.Timer中任务运行。

each piece is a very small piece of the screen (1/2000'th of it). The animation draws one piece every millisecond by changing the pixels in the buffered image and calling reaint(). So at the entire screen changes every 2 seconds. The animation is run in a java.util.Timer task.

的缓冲的图像不加速,是不挥发的。我设置它的优先级为1。

The buffered image is not accelerated and is not volatile. I set it's priority to 1.

框架根窗格进行了优化。两者的正面和背面缓冲器被加速,但不挥发

The frame root pane is optimized. Both the front and back buffer are accelerated but not volatile.

这工作正常。

剖析表明,几乎所有的grahics时间是花在绘制缓冲图像正如人们所期望,用一些肮脏的矩形似乎并没有帮助减少油漆的时间。

Profiling indicates that almost all of the grahics time is spend drawing the buffered image as one would expect, Using some dirty rectangles does not seem to help reduce the paint time.

如果我夹了缓冲的图像与它的确切形状的绘制,那块被画和屏幕的其他部分变为白色。

If I clip the drawing of the buffered image with it's exact shape, that piece gets painted and the rest of the screen turns white.

我想什么是有屏幕的其余部分保持它的方式,只是有截取的形状得到画的。

What I want to is to have the rest of the screen stay the way it was and just have the clipped shape get painted.

制作的像素,每件需要调合10层,所以有一些计算方面所做的工作。
可以/应该在这一个AWT计时器线程可以做的更好?

Making the pixels for each piece requires blending 10 layers, so there is some computation done there. could/should this be done better in an awt timer thread?

或者我应该用画布和更新伎俩 http://java.sun.com/products/jfc/tsc/articles/painting/src/UpdateDemo.java

Or should i use a canvas and the update trick http://java.sun.com/products/jfc/tsc/articles/painting/src/UpdateDemo.java

我所看到的建议,包括Toolkit.getDefaultToolkit()setDynamicLayout(真)。 System.setProperty(sun.awt.noerasebackground,真);

I have seen suggestion that include Toolkit.getDefaultToolkit().setDynamicLayout(true); System.setProperty("sun.awt.noerasebackground","true");

其他建议包括paintimmedialtely和JComponent的子类,而不是JPanel的。

other suggestions include paintimmedialtely, and subclassing JComponent instead of JPanel.

我觉得这一切有点混乱。

I find this all somewhat confusing.

我想保持这种独立于操作系统的尽可能多的,但应用程序将在Windows 7上运行的大部分

I would like to keep this OS independent as much as possible, but the app will run mostly on windows 7.

什么是下一个(小)的逻辑,我在这里走一步呢?

What is the next (small) logical step for me to take here?

更新:使用画布(不更新伎俩)显着降低花费绘制缓冲图像的时间。取而代之的是正对事件探查器的顶线,我无法找到它!我可能会做比我更应该当我使用的面板。

Update: Using a canvas (without the update trick) remarkably reduced the time spent drawing the buffered image. Instead of this being on the top line of the profiler, i can't find it! i may be doing more than i should when i use the panel.

推荐答案

下面是一些建议:


  • 严格审查,需要重绘()每毫秒;尤其是看到如果一些更新可能被合并。

  • Critically examine the need to repaint() every millisecond; in particular, see if some updates may be coalesced.

的java .swing.Timer ,这使得对EDT,支持合并事件。

Consider the convenience of java.swing.Timer, which renders on the EDT and supports coalescing events.

拨打的drawImage()是最快的,当不需要缩放,如本的 AnimationTest

Calls to drawImage() are fastest when no scaling is required, as shown in this AnimationTest.

总是可能$ P $对 - 计算图像的程度,如在此建议 KineticModel ,说明几个动画技术。

Always pre-compute images to the extent possible, as suggested in this KineticModel that illustrates several animation techniques.

TexturePaint KineticModel 使用,也显示的here

IndexColorModel的,图文并茂这里,可能是适用。

IndexColorModel, illustrated here, may be applicable.

这是 SSCCE 将让你的各种方法,便于分析隔离开来。

An sscce will allow you to isolate various approaches for easier profiling.

这篇关于我如何加快这一挥杆动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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