Nesting ShapeRenderer.begin/end in SpriteBatch.beg

2019-06-20 05:08发布

Is it possible to draw shapes by using ShapeRenderer between SpriteBatch begin and end calls.

I have tried but no result, only SpriteBatch textures are drawn, no shape is on the scene. Sample code is as followed below :

shapeRenderer.begin(ShapeType.FilledCircle);
shapeRenderer.setColor(0f, 1f, 0f, 1f);
shapeRenderer.filledCircle( 100, 100, 100);
shapeRenderer.end();

I have a orthographic camera created by these commands :

camera = new OrthographicCamera(1, Gdx.graphics.getHeight() / Gdx.graphics.getWidth());
camera.setToOrtho(true);

1条回答
霸刀☆藐视天下
2楼-- · 2019-06-20 05:35

Both ShapeRenderer and SpriteBatch set state in OpenGL that they expect to remain constant during their use. Nesting them can create problems. See this post in the badlogic forum.

This should probably be spelled out a bit more clearly in the docs.

查看更多
登录 后发表回答