javaimagegame-enginelighting2.5d

Darkening Sprites at distance Java


I have written a fully functional first-person-shooter (2.5D styled), though I'd like for sprites to be darkened at a distance from the camera(inverse-square function).

I've got the math down, but with little experience using BufferedImages, I do not know how to go about lowering pixel values (with alpha) or simply tinting them black.

Note: I am also buffering to a canvas(Image) with a Graphics2D

All insight is appreciated.


Solution

  • To darken a bufferedimage, you can just use a rescaleop. This snippet will darken it by 20%.

    float factor = .8f; 
    RescaleOp op = new RescaleOp(factor, 0, null);
    image= op.filter(bufferedImage, null);