So i have this particle engine which worked great. Now that I am trying to make them fade like good little particles, the performance is shot.
here is my drawing code before and after. Before had fantastic performance, after is choppy and bad.
Before:
public void draw(Graphics2D g) {
Iterator i = particles.iterator();
while (i.hasNext()) {
Particle p = (Particle)i.next();
g.setColor(p.getColor());
g.drawRect((int)p.getX()-p.getSize()/2,
(int)p.getY()-p.getSize()/2,
p.getSize(), p.getSize());
}
}
After:
public void draw(Graphics2D g) {
Composite c = g.getComposite();
Iterator i = particles.iterator();
while (i.hasNext()) {
Particle p = (Particle)i.next();
g.setColor(p.getColor());
g.setComposite(AlphaComposite.getInstance(
AlphaComposite.SRC_OVER, p.getAlpha()));
g.drawRect((int)p.getX()-p.getSize()/2,
(int)p.getY()-p.getSize()/2,
p.getSize(), p.getSize());
}
g.setComposite(c);
}
I am not aware of the performance compared to other ways to do any of that realy, so any way to make it not be terrible would be great.