LibGDX pixmap未正确更新像素

LibGDX pixmap未正确更新像素,libgdx,pixmap,Libgdx,Pixmap,我正在尝试使用Pixmap在LibGDX中创建“可破坏”地形(2D)。 但是,我正在设置的颜色不能正确显示在屏幕上 完整源代码(颜色当前用于调试,在版本中应为alpha=0): 公共类地形扩展{ 私人雪碧; 私有纹理; 私有Pixmap-myMap; 公共地形(纹理,矢量2位置) { 设置位置(位置x,位置y); 如果(!texture.getTextureData().isPrepared()){ texture.getTextureData().prepare(); } //最终产品将从纹理

我正在尝试使用Pixmap在LibGDX中创建“可破坏”地形(2D)。 但是,我正在设置的颜色不能正确显示在屏幕上

完整源代码(颜色当前用于调试,在版本中应为alpha=0):

公共类地形扩展{
私人雪碧;
私有纹理;
私有Pixmap-myMap;
公共地形(纹理,矢量2位置)
{
设置位置(位置x,位置y);
如果(!texture.getTextureData().isPrepared()){
texture.getTextureData().prepare();
}
//最终产品将从纹理中获取原始图像以创建pixmap
//myMap=texture.getTextureData().consumePixmap();
myMap=new Pixmap(400400,Pixmap.Format.rgba888);
myMap.setBlending(Pixmap.Blending.SourceOver);
myMap.setColor(Color.BLUE);
填充矩形(0,040400);
myTexture=新纹理(myMap,Pixmap.Format.rgba888,false);
mySprite=新精灵(myTexture);
}
公共void removePixels(列出像素)
{
myMap.setColor(Color.GREEN);
myMap.fillCircle(1,1,1);
设置颜色(颜色为黄色);
用于(矢量2像素:像素){
myMap.fillCircle((int)pixel.x,(int)pixel.y,1);//工作正常,但为黑色?
myMap.drawPixel((int)pixel.x,(int)pixel.y,255)//不工作
}
myTexture=新纹理(myMap,Pixmap.Format.rgba888,false);
mySprite=新精灵(myTexture);
System.out.println(“删除像素”);
}
@凌驾
公共作废绘制(批次批处理、浮点parentAlpha){
batch.draw(mySprite,getX(),getY(),mySprite.getWidth(),mySprite.getHeight());
//batch.draw(myMap,getX(),getY(),myMap.getWidth(),myMap.getHeight());
}
@凌驾
公共空间处置(){
dispose();
}
由于某些原因,在fillCircle中绘制的形状始终为黑色,而使用drawPixel绘制的像素甚至不会更新(保持原始颜色)。
如何在LibGDX中设置像素(alpha为0)(最好不使用glsl)

当您调用
drawCircle(x,y,1)
时,您正在传递RGBA8888颜色1,这相当于我认为的R=0,G=0,B=0,a=1/255。当您调用
drawPixel((int)pixel.x,(int)pixel.y,255)
,您正在传入RGBA8888 color 255,我认为它是R=0、G=0、B=0、A=1。在这两种情况下,调用都会忽略您在pixmap上设置的最后一种颜色。请使用这些方法的版本,这些方法不采用color参数


我看到了一些其他错误。如果不处理旧的纹理,每次调用
myTexture=new texture(…)
时都会泄漏纹理。但实际上,您应该只将更新的像素贴图绘制到纹理,这可能会更快。
myTexture.draw(myMap,0,0)
此外,如果您没有使用
Sprite.draw
,则没有理由使用Sprite对象。如果您使用
batch.draw
绘制Sprite,您可能还需要使用纹理区域。

我调用的是fillCircle,而不是drawCircle(第三个参数(1)是此圆的半径)。此外,drawPixel()调用不适用于任何参数(尝试0(为空)、255、1024和2048)。我使用精灵的原因与碰撞有关&例如,游戏中的所有对象都有精灵,因此在这里使用精灵比重写碰撞更容易。如果我的纹理已经使用我的pixmap作为其源,我是否需要“绘制到纹理”?
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();
}