fast java2d translucency

Posted by mdriesen on Game Development See other posts from Game Development or by mdriesen
Published on 2013-11-02T13:40:37Z Indexed on 2013/11/02 16:02 UTC
Read the original article Hit count: 242

Filed under:
|
|

I'm trying to draw a bunch of translucent circles on a Swing JComponent. This isn't exactly fast, and I was wondering if there is a way to speed it up. My custom JComponent has the following paintComponent method:

public void paintComponent(Graphics g) {
    Rectangle view = g.getClipBounds();

    VolatileImage image = createVolatileImage(view.width, view.height);
    Graphics2D buffer = image.createGraphics();
    // translate to camera location
    buffer.translate(-cx, -cy);
    // renderables contains all currently visible objects
    for(Renderable r : renderables) {
        r.paint(buffer);
    }
    g.drawImage(image.getSnapshot(), view.x, view.y, this);
}

The paint method of my circles is as follows:

public void paint(Graphics2D graphics) {
    graphics.setPaint(paint);
    graphics.fillOval(x, y, radius, radius);
}

The paint is just an rgba color with a < 255:

Color(int r, int g, int b, int a)

It works fast enough for opaque objects, but is there a simple way to speed this up for translucent ones?

© Game Development or respective owner

Related posts about java

Related posts about transparency