在 PlayN 中以编程方式淡入图像
我正在使用 PlayN 开发一款游戏,有一点我想拍摄一张图像(目前为 PNG 格式,已经有 8 位 alpha),并且我想将图像乘以一个额外的 alpha 因子,基于我的代码中的值。
具体来说,我有一张当前位于 ImageLayer 中的脸部图片,我想要的效果是这样的:
void init() {
faceImage = assetManager().getImage("images/face.png");
graphics().rootLayer().add(faceImage);
}
void update(float deltaMilliseconds) {
// start at fully transparent, fade to fully opaque
float transparency = calcTransparency(deltaMilliseconds);
faceImage.setTransparency(transparency);
}
我希望有某种方法可以对 GroupLayers 和混合模式进行一些处理,也许可以将图像的 CanvasLayer 涂有纯白色矩形,其透明度由我的代码控制,但对我来说,这是否是实现看似相当常见的效果的最佳方法并不明显。
I'm working on a game using PlayN, and there's a bit where I would like to take an image (which is currently in PNG format, with 8-bit alpha already) and I would like to multiply the image by an additional alpha factor, based on a value from my code.
Specifically, I have a picture of a face that currently lives in an ImageLayer, and the effect that I would like would be to have something like this:
void init() {
faceImage = assetManager().getImage("images/face.png");
graphics().rootLayer().add(faceImage);
}
void update(float deltaMilliseconds) {
// start at fully transparent, fade to fully opaque
float transparency = calcTransparency(deltaMilliseconds);
faceImage.setTransparency(transparency);
}
I expect that there's some way to do some trickiness with GroupLayers and blend modes, perhaps blending the image with a CanvasLayer painted with a solid white rectangle with transparency controlled by my code, but it's not obvious to me if that's the best way to achieve what seems like a pretty common effect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只想将图像从完全透明淡入为完全不透明,则只需执行以下操作:
其中 alpha 范围从 0(完全透明)到 1(完全不透明)。
If you just want to fade the image in from fully-transparent to fully-opaque, then just do the following:
Where alpha ranges from 0 (fully transparent) to 1 (fully opaque).