I've made a game that uses ShapeRenderer
for making colorized lines. This worked fine, but when I start to import images the colored lines suddenly became black. Worst of all: When I'm using a background the lines doesn't show at all, and yes, i'm drawing it in the right order....
Code for importing and rendering the images:
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();
}
But when I remove the code for rnedering the background and the pictures the lines will show up and in the right color....
Please help!!
EDIT: Drawing with the ShapeRenderer
looks something like this (Don't have to put everything in):
public void draw() {
shaperenderer.begin(ShapeType.Line);
shaperenderer.setColor(Color.RED);
shaperenderer.line(1, 1, 100, 100);
shaperenderer.end();
}
You cannot nest objects that depend on OpenGL context. Specifically, you are nesting a ShapeRenderer.begin()
within a SpriteBatch.begin()
. If you change render to look like this:
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With