Chandrasekhar Malladi
Chandrasekhar Malladi

Reputation: 351

Increasing the width of line drawn using Shape Renderer in LibGDX

I am drawing a line using Shape Renderer in LibGDX and i am using Orthographic Camera in my code, so to increase the width i used

camera = new OrthographicCamera();
int lineWidth = 8; // pixels
Gdx.gl10.glLineWidth(lineWidth / camera.zoom);

Now, I get a wider line. But the problem arises when the screen power goes off and then turns on, the line becomes the normal one again. How to keep the width constant?

Upvotes: 11

Views: 13073

Answers (2)

ShapeRenderer has the method rectLine that is intended to be used to draw thick lines. It draws a rotated filled rectangle with the smaller opposite sides centered on the points passed to it (as coordinates or as Vector2 objects). The method has the parameter width to set the line width.

You can see the documentation here

Example:

shapeRenderer.rectLine(new Vector2(x1,y1),new Vector2(x2,y2),lineWidth);

Upvotes: 22

Daahrien
Daahrien

Reputation: 10320

As you can see here:
libgdx Shaperenderer line .. How to draw line with a specific width
And here:
Libgdx gl10.glLineWidth()
And here:
Why Libgdx Gdx.gl10.glLineWidth(width); does not react to change projection properities

Playing with the line width in the shaperenderer isn't the best way to do what you want to achieve.

Try using a 1x1 white TextureRegion (you can change the color the Batch draws it with later), and draw it with the width and height that you desire:

batch.draw(region, x, y, width, height);

Upvotes: -1

Related Questions