Yes I know that java2D is really bad for lights and I did not show how I did my little lighting thing, I just wanted to know if anyone came up with some interesting ways of trying light in java2D.
Oh and the left 4k dead game is freaking awesome. Any idea how the light is done in that?
And here is they way I got some light working.
public class MyPanel extends JPanel
{
public void paintComponent(Graphics g)
{
Rectangle2D shape = new Rectangle.Double(x-(size/2),y-(size/2),size,size);
Graphics2D g2d = (Graphics2D)g;
g2d.setClip(shape);
g2d.drawImage(images[random], x-(size/2),y-(size/2),size, size,null);
g2d.drawImage(images[0], 0,0, frame.getWidth(),frame.getHeight(),null);
g2d.setClip(null);
drawLight(g);
g2d.dispose();
g.setColor(Color.yellow);
g.drawString("FPS: " + fps, 15,15);
g.dispose();
}
}
public void drawLight(Graphics g)
{
Graphics2D g2d = (Graphics2D) g.create();
Composite alphaComp;
alphaComp = AlphaComposite.getInstance(
AlphaComposite.DST_ATOP, 1f);
g2d.setComposite(alphaComp);
g2d.drawImage(images[random], x-(size/2),y-(size/2),size, size,null);
alphaComp = AlphaComposite.getInstance(
AlphaComposite.SRC_OVER, 0f);
g2d.setComposite(alphaComp);
g2d.drawImage(images[random], x-(size/2),y-(size/2),size, size,null);
g2d.dispose();
}
I just looked at it again and it works rather well. If you want a single light point it is not too bad. The second alphaComosite in the drawLight method is if you want to use any of the color in the light texture/image.