我正在尝试使用 Pixmap 在 LibGDX 中创建“可破坏”地形(2D)。但是,我设置的颜色没有正确显示在我的屏幕上。
完整源代码(颜色当前用于调试,发布时应为 alpha=0):
public class Terrain extends Actor implements Disposable {
private Sprite mySprite;
private Texture myTexture;
private Pixmap myMap;
public Terrain(Texture texture, Vector2 position)
{
setPosition(position.x, position.y);
if (!texture.getTextureData().isPrepared()) {
texture.getTextureData().prepare();
}
// Final product will take original image from a texture to create pixmap
// myMap = texture.getTextureData().consumePixmap();
myMap = new Pixmap(400, 400, Pixmap.Format.RGBA8888);
myMap.setBlending(Pixmap.Blending.SourceOver);
myMap.setColor(Color.BLUE);
myMap.fillRectangle(0, 0, 400, 400);
myTexture = new Texture(myMap, Pixmap.Format.RGBA8888, false);
mySprite = new Sprite(myTexture);
}
public void removePixels(List<Vector2> pixels)
{
myMap.setColor(Color.GREEN);
myMap.fillCircle(1,1,1);
myMap.setColor(Color.YELLOW);
for (Vector2 pixel:pixels) {
myMap.fillCircle((int)pixel.x, (int)pixel.y, 1); // Works, but is Black?
myMap.drawPixel((int)pixel.x, (int)pixel.y, 255) // Does not work
}
myTexture = new Texture(myMap, Pixmap.Format.RGBA8888, false);
mySprite = new Sprite(myTexture);
System.out.println("Pixels Removed");
}
@Override
public void draw(Batch batch, float parentAlpha) {
batch.draw(mySprite, getX(), getY(), mySprite.getWidth(), mySprite.getHeight());
// batch.draw(myMap, getX(), getY(), myMap.getWidth(), myMap.getHeight());
}
@Override
public void dispose() {
myMap.dispose();
}
由于某种原因,在 fillCircle 中绘制的形状始终为黑色,而使用 drawPixel 绘制的像素似乎甚至没有更新(保持原始颜色)。如何在 LibGDX 中设置像素(alpha 为 0)?(最好不使用 glsl)