Colors libgdx多边形精灵批绘制填充多边形

Colors libgdx多边形精灵批绘制填充多边形,colors,libgdx,rendering,textures,polygon,Colors,Libgdx,Rendering,Textures,Polygon,我需要绘制填充颜色的多边形,但我不知道如何正确创建纹理,以便batch绘制 这是我的密码 public class VisualComponent implements Component, Pool.Poolable { public float[] vertices = new float[1]; public short[] triangles = new short[1]; @Override public void reset(

我需要绘制填充颜色的多边形,但我不知道如何正确创建纹理,以便batch绘制 这是我的密码

public class VisualComponent implements Component, Pool.Poolable {
       public float[] vertices = new float[1];
       public short[] triangles = new short[1];

       @Override
       public void reset() {
           vertices = new float[1];
           triangles = new short[1];
       }
}
在这里,我正在创建我想要绘制的实体

    Entity source = engine.createEntity();
    TransformComponent transformComponent = engine.createComponent(TransformComponent.class);
    VisualComponent visualComponent = engine.createComponent(VisualComponent.class);
    float redColorBits = Color.RED.toFloatBits();
    visualComponent.vertices = new float[]{
            0, 0, redColorBits,
            10, 0, redColorBits,
            10, 10, redColorBits,
            0, 10, redColorBits
    };

    visualComponent.triangles = new short[]{
            0, 1, 2,
            0, 2, 3
    };

    source.add(transformComponent);
    source.add(visualComponent);
    engine.addEntity(source);
这是渲染系统的processEntity方法

@Override
protected void processEntity(Entity entity, float deltaTime) {
    TransformComponent transformComponent = tcm.get(entity);
    VisualComponent visualComponent = vcm.get(entity);

    batch.draw(new Texture(1, 1, Pixmap.Format.RGBA8888),
            visualComponent.vertices, 0, visualComponent.vertices.length,
            visualComponent.triangles, 0, visualComponent.triangles.length);

}

此外,我需要一个技巧,如何正确地重用我的纹理,而不是总是重新创建它。Thx

好的,我继承了PolygonSpriteBatch并为draw函数添加了1x1白色像素纹理,下面是运行良好的代码

public class TexturedPolygonSpriteBatch extends PolygonSpriteBatch {
private Texture texture;

    public TexturedPolygonSpriteBatch() {
        super();
        initTexture();
    }

    public void draw(float[] polygonVertices, int verticesOffset, int verticesCount, 
short[] polygonTriangles,
                     int trianglesOffset, int trianglesCount) {
        super.draw(texture, polygonVertices, verticesOffset, verticesCount, 
polygonTriangles, trianglesOffset, trianglesCount);
    }

    @Override
    public void dispose() {
        texture.dispose();
        super.dispose();
    }

    private void initTexture() {
        Logger.log(getClass(), "Initializing 1x1 white texture");
        Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
        pixmap.setColor(Color.WHITE);
        pixmap.fill();
        texture = new Texture(pixmap);
        pixmap.dispose();
    }
}
实际上,给纹理加上白色是很重要的,因为白色包含所有颜色,如果我设置红色,只有红色可以在那里绘制,想想这有点奇怪,但是woodoo工作了。)