【发布时间】:2013-02-15 07:51:44
【问题描述】:
我创建了一个AnimatedSprite 类,它绘制了一个特定的TextureRegion。有时我需要一个 tint 颜色效果,所以我设置(this.color 是我的AnimatedSprite 的一个Color 字段):
super.draw(batch, parentAlpha);
batch.setColor(this.color);
batch.draw(this.frames[this.currentFrame], x, y, originX, originY, width, height, scaleX, scaleY, rotation)
batch.setColor(Color.WHITE);
但是,当我将AnimatedSprite 的颜色设置为黑色或任何颜色时,其他所有颜色都具有该色调。我什至尝试flush(),结束批次并开始一个新的,等等......但似乎没有任何效果。
请帮我正确应用色调效果。我会很感激任何想法。
【问题讨论】:
-
这是AnimatedSprite
draw方法的主体?它看起来正确,看起来像Image.java 绘制方法。也许还有别的? this.color 是否在其他地方使用过? -
@P.T.看到您的评论后,我还查看了
Imageclass。Image类甚至没有重置批次的颜色,所以我尝试在我的代码中删除它。this.color没有在其他地方使用,我也给出了 r g b 值而不是整个颜色实例。但是,我的整个屏幕仍然是一种颜色。 -
@P.T.谢谢你的提示。我发现了问题。因为在初始化时,我将 Sprite 的颜色设置为 Color.WHITE(libgdx 的),所以我的每个 AnimatedSprite 都指向相同的颜色!
-
我也这样做了。我添加了一个答案,以便其他人会看到这个答案。如果您有机会也添加一些“将颜色设置为黑色”的代码。
标签: java sprite libgdx tint spritebatch