VolatileImages losing their contents is part of the API; your code has to account for it. (though I wish the API had been designed differently so this wasn’t necessary…)
Have a read of the volatile image tutorial.
As for your specific problem:
- don’t recreate the scratch VolatileImage - create one large enough for your largest sprite & keep hold of it.
- make sure all your drawing operations are being accelerated by using the java2d logging/tracing options
If you want the flash itself to be alpha’ed, then you should use the DST_ATOP rule instead.
It’ll maintain your source’s transparency channel but composite the colour channels of source & destination.
Here’s a little test app. I knocked up the last time this thread was touched. Forgive the lack of documentation & crude means of animating, it was hacked together 
Oh, and don’t use this as an example of how to do the compositing in a performant manner - this is purely a visualization tool for the compositing rules.
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.MultipleGradientPaint.CycleMethod;
import java.awt.RadialGradientPaint;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class CompositeTest extends JPanel {
/**
*
*/
private static final long serialVersionUID = 1L;
public enum AlphaCompositeRules {
CLEAR(AlphaComposite.CLEAR),
SRC(AlphaComposite.SRC),
DST(AlphaComposite.DST),
SRC_OVER(AlphaComposite.SRC_OVER),
DST_OVER(AlphaComposite.DST_OVER),
SRC_IN(AlphaComposite.SRC_IN),
DST_IN(AlphaComposite.DST_IN),
SRC_OUT(AlphaComposite.SRC_OUT),
DST_OUT(AlphaComposite.DST_OUT),
SRC_ATOP(AlphaComposite.SRC_ATOP),
DST_ATOP(AlphaComposite.DST_ATOP),
XOR(AlphaComposite.XOR);
private int rule;
private AlphaCompositeRules(int rule) {
this.rule = rule;
}
public AlphaComposite getInstance() {
return getInstance(1.0f);
}
public AlphaComposite getInstance(float alpha) {
return AlphaComposite.getInstance(rule, alpha);
}
};
private static final int IMG_SIZE = 64;
private BufferedImage sprite = new BufferedImage(IMG_SIZE ,IMG_SIZE , BufferedImage.TYPE_INT_ARGB);
private BufferedImage scratch = new BufferedImage(IMG_SIZE, IMG_SIZE, BufferedImage.TYPE_INT_ARGB);
public CompositeTest() {
setBackground(Color.black);
Graphics2D g2d = sprite.createGraphics();
g2d.setPaint(new RadialGradientPaint(new Rectangle2D.Float(0,0,IMG_SIZE,IMG_SIZE), new float[]{0.0f,1.0f},new Color[]{Color.WHITE, Color.BLUE}, CycleMethod.NO_CYCLE));
g2d.setClip(new Ellipse2D.Float(0,0,IMG_SIZE,IMG_SIZE));
g2d.fillRect(0, 0, IMG_SIZE, IMG_SIZE);
g2d.dispose();
}
public Dimension getPreferredSize() {
return new Dimension(IMG_SIZE *2, IMG_SIZE *(AlphaCompositeRules.values().length+1));
}
private void clear(BufferedImage img, Color c) {
Graphics2D g = img.createGraphics();
g.setColor(c);
g.setComposite(AlphaComposite.Src);
g.fillRect(0,0,img.getWidth(), img.getHeight());
g.dispose();
}
private int alpha = 0;
private int alphaDelta = 1;
public void paint(Graphics g) {
super.paint(g);
alpha+=alphaDelta;
if(alpha==255 || alpha==0) {
alphaDelta=-alphaDelta;
}
clear(scratch, new Color(255,0,0,alpha));
g.drawImage(scratch, 0, 0, null);
g.drawImage(sprite, IMG_SIZE, 0, null);
g.setColor(Color.white);
g.drawString("\u03B1=" + alpha, 0, IMG_SIZE/2);
for(int i = 0;i < AlphaCompositeRules.values().length;i++) {
clear(scratch, new Color(255,0,0,alpha));
Graphics2D scratchG = scratch.createGraphics();
scratchG.setComposite(AlphaCompositeRules.values()[i].getInstance());
scratchG.drawImage(sprite, 0, 0, null);
scratchG.dispose();
g.drawImage(scratch, IMG_SIZE, (i+1)*IMG_SIZE,null);
g.setColor(Color.white);
g.drawString(AlphaCompositeRules.values()[i].toString(), 0, (i+1)*IMG_SIZE+IMG_SIZE/2);
}
repaint();
}
public static void main(String[]args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().add(new CompositeTest());
frame.pack();
frame.setVisible(true);
}
}