I am creating a game that involves drawing on the order of 1000 filled circles, of radii between 2 - 10 pixels, onto a large JPanel at a frequency of 50Hz.
How I am currently doing this is by drawing each circle by calling the drawOval method via the JPanel itself. This, however, is very slow and somehow manages to increase the game running time by 50%.
So I thought of making use of a BufferedImage: create the buffered image and draw the filled circles on the buffered image instead. Then draw the entire buffered image onto the JPanel in one go. Will this approach be any faster than my original method? Is the use of drawOval itself for the 1000 or so times slow in both cases?
I suspect a lot of processing is wasted by printing the same pixels again whenever such pixels have not changed colour. Is there a way to avoid repainting such redundant pixels?
setBufferStrategy
. – user1803551