libgdx:当我使用Shaperenderer添加actor时,为什么我的所有actor都不渲染?

时间:2016-07-11 18:33:44

标签: android opengl-es libgdx

我将一个演员添加到一个组中,导致我的所有演员都不显示。 actor的draw方法是使用Shaperenderer,如下所示

@Override
public void draw(Batch batch, float parentAlpha) {
    super.draw(batch, parentAlpha);

    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
    shapeRenderer.rectLine(ax, ay, bx, by, 5);
    shapeRenderer.end();
}

每当我删除演员时,该组中的所有其他演员都会显示没有问题。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:3)

You can't interleave the begin/end of a SpriteBatch and a ShapeRenderer. When an actor's draw method is called, begin() has already been called on the SpriteBatch. So you can fix your draw() method like this:

@Override
public void draw(Batch batch, float parentAlpha) {
    super.draw(batch, parentAlpha);
    batch.end();
    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
    shapeRenderer.rectLine(ax, ay, bx, by, 5);
    shapeRenderer.end();
    batch.begin();
}

Also make sure you've set the projection matrix for the shape renderer.

Note that you are causing an extra SpriteBatch flush for every actor that does this.