UIOverlay problem

Hi!

I am making my own “game” to test my skills 8).
Now i am making the HUD and I am using UIOverlay to paint it.
The only problem for now is that the clearRect(x, y, width, height) (which is removing all previous graphics) is very slowly.

How to do it faster?

Here is the code:



public void paint(Graphics2D poGraphics2D) {
        // Clear All Previous
        poGraphics2D.setBackground(moTransparent);
        // This is slow
        poGraphics2D.clearRect(0, 0, width, height);
        
        // Test Drawing
        poGraphics2D.setColor(Color.WHITE);
        poGraphics2D.drawString("" + System.currentTimeMillis(), poGraphics2D.getFontMetrics().getMaxAscent(), height - poGraphics2D.getFontMetrics().getMaxAscent());
        
        // FPS
        poGraphics2D.setColor(Color.WHITE);
        poGraphics2D.drawString("FPS : " + miFPS, poGraphics2D.getFontMetrics().getMaxAscent(), height - poGraphics2D.getFontMetrics().getMaxAscent() * 2);
        
        // Transparency
        poGraphics2D.setComposite(moComposite);
        
        // Cross-Hair
        poGraphics2D.setColor(moCrossHairColor);
        poGraphics2D.fillOval(639, 511, 2, 2);
        poGraphics2D.drawLine(620, 510, 638, 492);
        poGraphics2D.drawLine(620, 514, 638, 532);
        poGraphics2D.drawLine(660, 510, 642, 492);
        poGraphics2D.drawLine(660, 514, 642, 532);
        
        // Radar
        poGraphics2D.setColor(Color.BLACK);
        poGraphics2D.drawOval(5, 5, 200, 200);
        poGraphics2D.setColor(Color.GREEN);
        poGraphics2D.fillOval(5, 5, 200, 200);
        poGraphics2D.setColor(Color.WHITE);
        poGraphics2D.fillRect(104, 5, 2, 105);
        
    }


If someone have got anything please reply!

Thanks

I do not know a way for clearing it faster than by using clearRect but you may can optimize yout code. There is a lot of static data in it (the lines, setting white color twice where once should be enough, calculating data that stays constant, setting nackground and clearing the full component). That needs to be done only once (at init time or in a separate setter). Also you simply may clear the changing data: the areas of text. For sure that will be small enhancemants but worth to try.

Just my two cents

By the way: what do you mean exactly by calling the clearing to be slow? Flickering (use double-buffering then)? Or updating only 1 or two times during each second? Than you should take in account that swing updates the real view of the gui representation within intervals and not as fast as possible …