Increasing the width of line drawn using Shape Renderer in LibGDX

喜夏-厌秋 提交于 2020-01-28 10:44:05

问题


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?


回答1:


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);



回答2:


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);


来源:https://stackoverflow.com/questions/18650619/increasing-the-width-of-line-drawn-using-shape-renderer-in-libgdx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!