I am making a 2D Java game and I'd like to darken stuff in the dark areas. I was wondering if I could use alphatransparent colors in a paintComponent
method. If not, does translucent PNGs work or is there effects for darkening images.
Thanks
Translucent fill in paintComponent
87 Views Asked by AudioBubble At
2
There are 2 best solutions below
0

You can use transparency/opacity in java.
Here you can find some basic info on the procedure. The important step is using an AlphaComposite
object to set the alpha value of your drawing
I would create a new BufferedImage of type TYPE_INT_ARGB, edit straight into the raster data, - set the color of your choice (with desired alpha), and just draw it after everything else, in your paint method. drawImage is pretty fast. And if you want to change the darkness colors, you can set the new alpha values on the fly directly into the data array of the image.