【问题标题】:Increasing the width of line drawn using Shape Renderer in LibGDX在 LibGDX 中增加使用 Shape Renderer 绘制的线条的宽度
【发布时间】:2013-09-06 05:35:51
【问题描述】:

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

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

现在,我得到了一个更宽的界限。但是当屏幕电源关闭然后再打开时,就会出现问题,线路又恢复正常。如何保持宽度不变?

【问题讨论】:

  • 编写相同的代码,除了在屏幕的恢复功能中初始化相机......这对你有用
  • 当我在恢复功能中初始化我的相机时,我的相机位置在我的屏幕上设置为 (0,0,0)。
  • 只写resume func的最后两行
  • 在resize函数中写对我有帮助!感谢您的帮助:)

标签: libgdx


【解决方案1】:

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

可以查看文档here

例子:

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

【讨论】:

    【解决方案2】:

    如您所见:
    libgdx Shaperenderer line .. How to draw line with a specific width
    在这里:
    Libgdx gl10.glLineWidth()
    在这里:
    Why Libgdx Gdx.gl10.glLineWidth(width); does not react to change projection properities

    在 shaperenderer 中使用线宽并不是实现您想要实现的目标的最佳方式。

    尝试使用 1x1 白色 TextureRegion(您可以更改 Batch 稍后绘制它的颜色),并使用您想要的宽度和高度进行绘制:

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

    【讨论】:

    • 你不可能只用 x、y、width 和 height 画一条线(除了垂直或水平的直线)......想想看。您至少必须旋转它...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-10
    相关资源
    最近更新 更多