1 回答
TA贡献1934条经验 获得超2个赞
要在 LibGDX 中以编程方式更改颜色,您需要使用带有白色像素的图像(png 或 jpg),您可以将图像分成两部分来实现此效果,一部分用于您不希望更改颜色的部分,另一部分用于你做的部分。这是一个例子:
代码:
public class ExampleGame extends InputAdapter {
SpriteBatch batch;
Color crownColor;
public ExampleGame() {
batch = new SpriteBatch();
crownColor = Color.WHITE;
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
crownColor = Color.RED;
return false;
}
public void render(TextureRegion player, TextureRegion crown) {
batch.begin();
batch.setColor(Color.WHITE); // Else player will be affected by crownColor too
batch.draw(player, 0, 0);
batch.setColor(crownColor);
batch.draw(crown, 0, 0);
batch.end();
}
}
添加回答
举报