How do I fade out one image and fade in another (Java)?

元气小坏坏 提交于 2019-12-03 20:08:24

You can use Trident to interpolate a property you define in your class. Then during painting you can use this property as alpha in AlphaComposite. Here you can find some examples for AlphaComposite.

EDIT: May be this can help you:

//define a property to animate
float opacity;

//define timeline for animation
Timeline timeline = new Timeline(this);
timeline.addPropertyToInterpolate("opacity", 1.0f, 0.0f);
timeline.play();

//inside painting 
...
Graphics2D g2d = (Graphics2D) g.create();
g2d.setComposite(AlphaComposite.SrcOver.derive(this.opacity));
g2d.drawImage(img1...);

g2d.setComposite(AlphaComposite.SrcOver.derive(1.0 - this.opacity));
g2d.drawImage(img1...);

g2d.dispose();
...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!