So here we go, my first ever post on a forum. And I’m really embarrassed about it because it is a very simple one still I can’t get my stupid head around it. I haven’t really worked with Java2D so far, let alone bufferedImages. So:
I’ve got an ever-changing buffered image, it represents the screen. This buffered image is drawn into the screen directly. There are many other buffered images that are drawn into this first big one. My problem is that when you try to move these smaller buffered images the screen behind doesn’t get cleared as it is a bufferedImage itself. I found one solution to this problem:
screenBuffer. setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f));
Rectangle2D.Double rect = new Rectangle2D.Double(0, 0, screen.width, screen.height);
screenBuffer. fill (rect);
So far so good, the main bufferedImage in the background gets cleared up, but I can’t draw ANYTHING into it anymore, can someone please tell me why?
Naively I tried to add one more line after the above code:
screenBuffer. setComposite(AlphaComposite.getInstance(AlphaComposite.BITMASK, 1.0f));
…and it didn’t work obviously. What I tried to do here is to clear all the pixels of the bufferedImage, then set the alpha back to normal so that anything added to screenBuffer after this line would get drawn.
Any solution for this? Thanks in advance.
Greg