我制作了一款使用ShapeRenderer
制作彩色线条的游戏。这很好,但是当我开始导入图像时,彩色线条突然变黑了。最糟糕的是:当我使用背景时,线条根本没有显示,是的,我正在以正确的顺序绘制它......
导入和渲染图像的代码:
Constructor(){
TextureAtlas atlas = new TextureAtlas(Gdx.files.internal("data/texture.atlas"));
AtlasRegion region = atlas.findRegion("path");
Sprite sprite = new Sprite(region);
}
..........................................
@Override
public void render() {
Gdx.gl.glClearColor(255, 255, 255, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
batch.begin();
background.draw(batch); // drawing the background
drawing.draw(); // drawing the lines
drawObjects(); // drawing some pictures
batch.end();
}
但是当我删除用于渲染背景和图片的代码时,线条会以正确的颜色显示....
请帮助!!
编辑:使用ShapeRenderer
绘图看起来像这样(不要把所有内容都放进去):
public void draw() {
shaperenderer.begin(ShapeType.Line);
shaperenderer.setColor(Color.RED);
shaperenderer.line(1, 1, 100, 100);
shaperenderer.end();
}
答案 0 :(得分:11)
您无法嵌套依赖OpenGL上下文的对象。具体来说,您正在ShapeRenderer.begin()
内嵌套SpriteBatch.begin()
。如果将渲染更改为如下所示:
batch.begin();
background.draw(batch); // drawing the background
batch.end(); // end spritebatch context to let ShapeRenderer in
drawing.draw(); // drawing the lines (with ShapeRenderer)
batch.begin();
drawObjects(); // drawing some pictures
batch.end();