In a 2D game I am working on, I am trying to make lighting by simply painting ovals over each other, starting with the smallest and moving on to the largest. The idea is that there is a distance and an intensity, where the distance is the radius of the reach of the light, and the intensity is the increase in radius of each circle (with the special case that the outer-most circle can never reach past the distance). Here is my code to do so:
@Override
public void paint(Graphics g) {
if (loc == null) {
return;
}
boolean finished = false;
int alpha = color.getAlpha() / (int) Math.ceil(distance / intensity);
for (int i = intensity; i <= distance; i += intensity) {
g.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha));
g.fillOval(loc.getX() + (distance - i) - 1, loc.getY() + (distance - i) - 1, i * 2, i * 2);
if (i + intensity > distance && !finished) {
i = distance - intensity;
finished = true;
}
}
}
My problem is that I keep trying different methods to ensure that the middle circle always has the given alpha, and non have yet worked. I have tried to figure out the behavior of the Graphics.drawOval() method, however I have been unable to do so. In this case, I have been using the test color of Aureolin (R: 253, G: 238, B: 0), with the alpha of 150. I was simply wondering if anyone had any ideas to solve this issue, as I have tested this code and found that with lower intensity values, the inner-most circle has lower alpha (although I have been unable to find a relationship as I have not been able to quantify the alpha at that point).
Any ideas?
Aucun commentaire:
Enregistrer un commentaire