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

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

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

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

        使用 libGDX 绘制填充多边形

        时间:2023-05-20
          <legend id='QcP9E'><style id='QcP9E'><dir id='QcP9E'><q id='QcP9E'></q></dir></style></legend>
        • <small id='QcP9E'></small><noframes id='QcP9E'>

        • <tfoot id='QcP9E'></tfoot>

                <tbody id='QcP9E'></tbody>

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

                <bdo id='QcP9E'></bdo><ul id='QcP9E'></ul>
                  本文介绍了使用 libGDX 绘制填充多边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我想用 libGDX 绘制一些(填充的)多边形.它不应该填充图形/纹理.我只有多边形的顶点(闭合路径)并尝试使用网格进行可视化,但在某些时候这不是最好的解决方案,我认为.

                  I want to draw some (filled) polygons with libGDX. It shoudn't be filled with a graphic/texture. I have only the vertices of the polygon (closed path) and tried to visualize with meshes but at some point this is not the best solution, I think.

                  我的矩形代码是:

                  private Mesh mesh;
                  
                  @Override
                  public void create() {
                      if (mesh == null) {
                          mesh = new Mesh(
                              true, 4, 0, 
                              new VertexAttribute(Usage.Position, 3, "a_position")
                          );
                          mesh.setVertices(new float[] { 
                              -0.5f, -0.5f, 0
                              0.5f, -0.5f, 0,
                              -0.5f, 0.5f, 0,
                              0.5f, 0.5f, 0 
                          });     
                      }
                  }
                  
                  // ...
                  
                  @Override
                  public void render() {
                      Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
                      mesh.render(GL10.GL_TRIANGLE_STRIP, 0, 4);
                  }
                  

                  有什么功能可以更简单地绘制填充多边形吗?

                  is there a function or something to draw filled polygons in an easier way?

                  推荐答案

                  这是一个绘制 2D 凹多边形的 libGDX 示例.

                  Here is a libGDX example which draws a 2D concave polygon.

                  PolygonSprite 定义类成员 PolygonSpriteBatch

                  PolygonSprite poly;
                  PolygonSpriteBatch polyBatch;
                  Texture textureSolid;
                  

                  创建实例,使用红色像素作为解决方法的 1x1 大小纹理.一个坐标数组 (x, y) 用于多边形的初始化.

                  Create instances, 1x1 size texture used with red pixel as workaround. An array of coordinates (x, y) is used for initialization of the polygon.

                  ctor() {
                      textureSolid = makeTextureBox(1, 0xFFFF0000, 0, 0); 
                      float a = 100;
                      float b = 100;
                      PolygonRegion polyReg = new PolygonRegion(new TextureRegion(textureSolid),
                        new float[] {
                          a*0, b*0,
                          a*0, b*2,
                          a*3, b*2,
                          a*3, b*0,
                          a*2, b*0,
                          a*2, b*1,
                          a*1, b*1,
                          a*1, b*0,
                      });
                      poly = new PolygonSprite(polyReg);
                      poly.setOrigin(a, b);
                      polyBatch = new PolygonSpriteBatch();
                  }
                  

                  绘制和旋转多边形

                  void draw() {
                      super.draw();
                      polyBatch.begin();
                      poly.draw(polyBatch);
                      polyBatch.end();
                      poly.rotate(1.1f);
                  }
                  

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

                  上一篇:在 libgdx 游戏中设置延迟 下一篇:使用 libgdx 的类的单元测试

                  相关文章

                  最新文章

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

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

                    1. <small id='yupUq'></small><noframes id='yupUq'>

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