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

        LibGDX 画线

        时间:2023-05-19

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

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

                <legend id='cGrHI'><style id='cGrHI'><dir id='cGrHI'><q id='cGrHI'></q></dir></style></legend>
              • <tfoot id='cGrHI'></tfoot>

                  <tbody id='cGrHI'></tbody>
              • <i id='cGrHI'><tr id='cGrHI'><dt id='cGrHI'><q id='cGrHI'><span id='cGrHI'><b id='cGrHI'><form id='cGrHI'><ins id='cGrHI'></ins><ul id='cGrHI'></ul><sub id='cGrHI'></sub></form><legend id='cGrHI'></legend><bdo id='cGrHI'><pre id='cGrHI'><center id='cGrHI'></center></pre></bdo></b><th id='cGrHI'></th></span></q></dt></tr></i><div id='cGrHI'><tfoot id='cGrHI'></tfoot><dl id='cGrHI'><fieldset id='cGrHI'></fieldset></dl></div>
                  本文介绍了LibGDX 画线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在尝试使用 libGDX 制作类似弹弓的东西.

                  I'm trying to make something like a slingshot using libGDX.

                  我的代码

                  if (Gdx.input.isTouched()) {
                  
                          ShapeRenderer sr = new ShapeRenderer();
                          sr.setColor(Color.BLACK);
                          sr.setProjectionMatrix(camera.combined);
                  
                          sr.begin(ShapeType.Line);
                          sr.line(player.getLeft().x, player.getLeft().y,
                                  Global.game_touch_position.x, Global.game_touch_position.y);
                          sr.line(player.getRight().x, player.getRight().y,
                                  Global.game_touch_position.x, Global.game_touch_position.y);
                          sr.end();
                  
                      }
                  

                  这样做我会得到输出这看起来很糟糕,如果我在我的 android 手机上调试,logcat 会被消息发送垃圾邮件

                  Doing this i will have the output This looks awful, and if I debug on my android phone , the logcat is spammed by the message

                  02-17 18:55:27.371: D/dalvikvm(7440): GC_CONCURRENT freed 1884K, 40% free 8287K/13635K, paused 15ms+2ms, total 40ms
                  

                  而且滞后,当我触摸屏幕时,我有 30 fps,当我不触摸时,我有 60...

                  And lags, I have like 30 fps when i touch the screen , and 60 when i don't...

                  我还需要画粗一点的线,所以当线变大时,我必须把它加粗,看起来很酷.

                  I also need to draw the line with a little bit of thickness, so when the line is bigger, i will have to make it thicker, to give a cool look.

                  在 libgdx 中绘制简单线条的最佳方法是什么?如果我找不到任何答案,我可能会从线的一点到另一点画圈......这看起来不错,但看起来不像弹弓......

                  Which is the best way to draw a simple line in libgdx ? If I won't find any answer probably i'm going to draw circles from a point of the line to the other..this would look ok , but won't look like a slingshot...

                  有什么帮助吗?

                  推荐答案

                  我只是在 helper 或 utils 类中有这样的东西.我通常用它来调试和可视化正在发生的事情.

                  I just have something like this in a helper or utils class. I usually use it for debugging and visualizing whats going on.

                  private static ShapeRenderer debugRenderer = new ShapeRenderer();
                  
                      public static void DrawDebugLine(Vector2 start, Vector2 end, int lineWidth, Color color, Matrix4 projectionMatrix)
                      {
                          Gdx.gl.glLineWidth(lineWidth);
                          debugRenderer.setProjectionMatrix(projectionMatrix);
                          debugRenderer.begin(ShapeRenderer.ShapeType.Line);
                          debugRenderer.setColor(color);
                          debugRenderer.line(start, end);
                          debugRenderer.end();
                          Gdx.gl.glLineWidth(1);
                      }
                  
                      public static void DrawDebugLine(Vector2 start, Vector2 end, Matrix4 projectionMatrix)
                      {
                          Gdx.gl.glLineWidth(2);
                          debugRenderer.setProjectionMatrix(projectionMatrix);
                          debugRenderer.begin(ShapeRenderer.ShapeType.Line);
                          debugRenderer.setColor(Color.WHITE);
                          debugRenderer.line(start, end);
                          debugRenderer.end();
                          Gdx.gl.glLineWidth(1);
                      }
                  

                  现在我可以轻松地从任何我喜欢的投影矩阵上画一条线.

                  Now I can easily draw a line from anywhere I like on any projection matrix I want.

                  HelperClass.DrawDebugLine(new Vector2(0,0), new Vector2(100,100), camera.combined);
                  

                  你想在其他 SpriteBatch 开始和结束之外绘制.如果您想在每帧中创建很多行,最好在单独的静态方法中开始和结束 ShapeRenderer,或者将其公开并根据您的需要自行完成.

                  You want to draw outside the other SpriteBatch begin and end. And if you want to make a lot of lines each frame you are better off beginning and ending the ShapeRenderer in a separate static method or make it public and do it yourself depending on your needs.

                  显然,您可以为更多形状或更多重载创建更多方法.

                  Obviously you can create more methods for more shapes or more overloads.

                  这篇关于LibGDX 画线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:单击 libGDX 中的 Actor 下一篇:库GDX .绘制多行文本

                  相关文章

                  最新文章

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

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

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