在 LibGDX 中增加使用 Shape Renderer 绘制的线条的宽度 [英] Increasing the width of line drawn using Shape Renderer in LibGDX

查看:20
本文介绍了在 LibGDX 中增加使用 Shape Renderer 绘制的线条的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 LibGDX 中的 Shape Renderer 绘制一条线,并且我在我的代码中使用正交相机,以便增加我使用的宽度

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?

推荐答案

ShapeRenderer 具有用于绘制粗线的方法 rectLine.它绘制一个旋转的填充矩形,较小的对边以传递给它的点为中心(作为坐标或作为 Vector2 对象).该方法有参数width来设置线宽.

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.

您可以查看文档 这里

例子:

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

这篇关于在 LibGDX 中增加使用 Shape Renderer 绘制的线条的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆