I am making a Java2D game, and I'm trying to alpha-blend layers of the same image to create something similar to blur.
Using AlphaComposite is really slow, and it's dropping the average framerate from 170 to 90, this might not look like a problem (since most games run at 60), but sometimes the framerate drops to lower than 45 (maybe because I'm using a bit more of my computer? not sure), and it seems like a lot for a single effect I'm trying to apply.
In my constructor, I have
AlphaComposite blurAlpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f); AlphaComposite opaque = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1);
then in the main loop: (to be clear, g is the Graphics2D object, and game is the pre-rendered image of the game)
g.setComposite(blurAlpha); g.drawImage(game, -1, 0, null); g.drawImage(game, 1, 0, null); g.setComposite(opaque);
At first I thought the framerate drop was due to drawing the image twice, but when I remove the
setComposite lines, the framerate goes up to 150.