Translucent fill in paintComponent

87 Views Asked by At

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

2

There are 2 best solutions below

0
On BEST ANSWER

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.

0
On

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