<small id='Ol6dJ'></small><noframes id='Ol6dJ'>

    <legend id='Ol6dJ'><style id='Ol6dJ'><dir id='Ol6dJ'><q id='Ol6dJ'></q></dir></style></legend>

    <i id='Ol6dJ'><tr id='Ol6dJ'><dt id='Ol6dJ'><q id='Ol6dJ'><span id='Ol6dJ'><b id='Ol6dJ'><form id='Ol6dJ'><ins id='Ol6dJ'></ins><ul id='Ol6dJ'></ul><sub id='Ol6dJ'></sub></form><legend id='Ol6dJ'></legend><bdo id='Ol6dJ'><pre id='Ol6dJ'><center id='Ol6dJ'></center></pre></bdo></b><th id='Ol6dJ'></th></span></q></dt></tr></i><div id='Ol6dJ'><tfoot id='Ol6dJ'></tfoot><dl id='Ol6dJ'><fieldset id='Ol6dJ'></fieldset></dl></div>

    • <bdo id='Ol6dJ'></bdo><ul id='Ol6dJ'></ul>

        <tfoot id='Ol6dJ'></tfoot>

        LIBGDX:如何使用 shaperenderer 绘制填充多边形?

        时间:2023-05-19

        1. <i id='2XGyz'><tr id='2XGyz'><dt id='2XGyz'><q id='2XGyz'><span id='2XGyz'><b id='2XGyz'><form id='2XGyz'><ins id='2XGyz'></ins><ul id='2XGyz'></ul><sub id='2XGyz'></sub></form><legend id='2XGyz'></legend><bdo id='2XGyz'><pre id='2XGyz'><center id='2XGyz'></center></pre></bdo></b><th id='2XGyz'></th></span></q></dt></tr></i><div id='2XGyz'><tfoot id='2XGyz'></tfoot><dl id='2XGyz'><fieldset id='2XGyz'></fieldset></dl></div>
                <tbody id='2XGyz'></tbody>
              • <tfoot id='2XGyz'></tfoot>
                • <bdo id='2XGyz'></bdo><ul id='2XGyz'></ul>
                • <legend id='2XGyz'><style id='2XGyz'><dir id='2XGyz'><q id='2XGyz'></q></dir></style></legend>

                  <small id='2XGyz'></small><noframes id='2XGyz'>

                  本文介绍了LIBGDX:如何使用 shaperenderer 绘制填充多边形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我已经使用顶点数组定义了一个形状:

                  I have defined a shape using an array of vertices:

                  float[] points =  new float[]{50,60,50,70,60,70, 60,60,50,60};
                  

                  我在这里画这个:

                  shapeRenderer.polygon(floatNew);
                  

                  这只是给出了形状的轮廓.
                  如何用颜色填充它?
                  谢谢

                  This just gives an outline of the shape.
                  How do I fill it with colour?
                  Thanks

                  推荐答案

                  目前ShapeRenderer支持多边形绘制(按线),但不支持填充.

                  Currently, ShapeRenderer supports polygon drawing (by line) but not filling.

                  这段代码在三角形上剪裁多边形,然后分别绘制每个三角形.

                  This code is clipping the polygon on triangles, and then drawing each triangle separately.

                  像这样编辑 ShapeRenderer.java:

                  Edit ShapeRenderer.java like this:

                  EarClippingTriangulator ear = new EarClippingTriangulator();
                  
                  public void polygon(float[] vertices, int offset, int count)
                  {
                      if (shapeType != ShapeType.Filled && shapeType != ShapeType.Line)
                          throw new GdxRuntimeException("Must call begin(ShapeType.Filled) or begin(ShapeType.Line)");
                      if (count < 6)
                          throw new IllegalArgumentException("Polygons must contain at least 3 points.");
                      if (count % 2 != 0)
                          throw new IllegalArgumentException("Polygons must have an even number of vertices.");
                  
                      check(shapeType, null, count);
                  
                      final float firstX = vertices[0];
                      final float firstY = vertices[1];
                      if (shapeType == ShapeType.Line)
                      {
                          for (int i = offset, n = offset + count; i < n; i += 2)
                          {
                              final float x1 = vertices[i];
                              final float y1 = vertices[i + 1];
                  
                              final float x2;
                              final float y2;
                  
                              if (i + 2 >= count)
                              {
                                  x2 = firstX;
                                  y2 = firstY;
                              } else
                              {
                                  x2 = vertices[i + 2];
                                  y2 = vertices[i + 3];
                              }
                  
                              renderer.color(color);
                              renderer.vertex(x1, y1, 0);
                              renderer.color(color);
                              renderer.vertex(x2, y2, 0);
                  
                          }
                      } else
                      {
                          ShortArray arrRes = ear.computeTriangles(vertices);
                  
                          for (int i = 0; i < arrRes.size - 2; i = i + 3)
                          {
                              float x1 = vertices[arrRes.get(i) * 2];
                              float y1 = vertices[(arrRes.get(i) * 2) + 1];
                  
                              float x2 = vertices[(arrRes.get(i + 1)) * 2];
                              float y2 = vertices[(arrRes.get(i + 1) * 2) + 1];
                  
                              float x3 = vertices[arrRes.get(i + 2) * 2];
                              float y3 = vertices[(arrRes.get(i + 2) * 2) + 1];
                  
                              this.triangle(x1, y1, x2, y2, x3, y3);
                          }
                      }
                  }
                  

                  这篇关于LIBGDX:如何使用 shaperenderer 绘制填充多边形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 Libgdx 中实现简单运动模糊的意外结果 下一篇:如何使用 libgdx 联系人监听器

                  相关文章

                  最新文章

                  1. <tfoot id='1kUVM'></tfoot>

                      <small id='1kUVM'></small><noframes id='1kUVM'>

                    1. <i id='1kUVM'><tr id='1kUVM'><dt id='1kUVM'><q id='1kUVM'><span id='1kUVM'><b id='1kUVM'><form id='1kUVM'><ins id='1kUVM'></ins><ul id='1kUVM'></ul><sub id='1kUVM'></sub></form><legend id='1kUVM'></legend><bdo id='1kUVM'><pre id='1kUVM'><center id='1kUVM'></center></pre></bdo></b><th id='1kUVM'></th></span></q></dt></tr></i><div id='1kUVM'><tfoot id='1kUVM'></tfoot><dl id='1kUVM'><fieldset id='1kUVM'></fieldset></dl></div>
                      <legend id='1kUVM'><style id='1kUVM'><dir id='1kUVM'><q id='1kUVM'></q></dir></style></legend>

                        <bdo id='1kUVM'></bdo><ul id='1kUVM'></ul>