<legend id='dH7vU'><style id='dH7vU'><dir id='dH7vU'><q id='dH7vU'></q></dir></style></legend>
    • <bdo id='dH7vU'></bdo><ul id='dH7vU'></ul>

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

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

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

        如何使用 Libgdx/Java 绘制文本?

        时间:2023-05-19

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

              <tbody id='Cx32K'></tbody>
              <tfoot id='Cx32K'></tfoot>
                <bdo id='Cx32K'></bdo><ul id='Cx32K'></ul>
                <legend id='Cx32K'><style id='Cx32K'><dir id='Cx32K'><q id='Cx32K'></q></dir></style></legend>

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

                  问题描述

                  限时送ChatGPT账号..

                  我在谷歌上搜索如何使用 Libgdx 绘制简单的 2D 文本时遇到了很多麻烦.以下是我目前整理的代码:

                  I've been having a lot of trouble Googling how to draw simple 2D text with Libgdx. Here is the code that I've put together so far:

                  SpriteBatch spriteBatch;
                  BitmapFont font;
                  CharSequence str = "Hello World!";
                  spriteBatch = new SpriteBatch();
                  font = new BitmapFont();
                  
                  spriteBatch.begin();
                  font.draw(spriteBatch, str, 10, 10);
                  spriteBatch.end();
                  

                  代码确实绘制了 Hello World 字符串,但是,它弄乱了我所有的其他绘图.他们在那里,只是被残忍地肢解,移动等等.我已经尝试了 Gdx.gl11.glPushMatrix()Gdx.gl11.glPopMatrix() 几乎每个语句子集.

                  The code does draw the Hello World string, however, it messes up all my other drawings. They are there, only brutally mutilated, and move and all that. I've tried Gdx.gl11.glPushMatrix() and Gdx.gl11.glPopMatrix() around just about every subset of statements.

                  我已将残缺的绘图缩小到 font.draw() 调用,如果将其取出,一切正常(但当然没有文字).

                  I've narrowed the mutilated drawings down to the font.draw() call, if that's taken out, everything works fine (but of course there is no text then).

                  推荐答案

                  我没有看到为文本绘制创建单独批处理的太多理由.使用 gdxVersion = '1.4.1'(在 Android Studio 中使用 gradle 构建)代码成功绘制文本:

                  I don't see much reason of creating separate batch for text drawing. Using gdxVersion = '1.4.1' (built with gradle in Android Studio) that code draws text successfully:

                  BitmapFont font = new BitmapFont(); //or use alex answer to use custom font
                  
                  public void render( float dt )
                    {
                      batch.setProjectionMatrix(camera.combined); //or your matrix to draw GAME WORLD, not UI
                  
                      batch.begin();
                  
                      //draw background, objects, etc.
                      for( View view: views )
                      {
                        view.draw(batch, dt);
                      }
                  
                      font.draw(batch, "Hello World!", 10, 10);
                  
                      batch.end();
                    }
                  

                  注意,这里你绘制的是游戏世界坐标,所以如果你的角色移动(例如在平台游戏中),文本也会移动.如果您想查看文本,它将被固定在屏幕上,例如 Label/TextField 或如何在不同的 UI 框架中调用它,而不是我建议使用 Stage(和 TextArea 用于文本),请参阅例如如何使用这里的舞台:http://www.toxsickproductions.com/libgdx/libgdx-basics-create-a-simple-menu/

                  Note, that here you draw in game world coordinates, so if your character moves (in platformer, for example), than text will move too. If you want to see text, that it will be fixed on screen, something like Label/TextField or how it is called in different UI frameworks, than I recommend to use Stage (and TextArea for text), see for example on how to use Stage here: http://www.toxsickproductions.com/libgdx/libgdx-basics-create-a-simple-menu/

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

                  上一篇:LibGDX 3D 提高性能 下一篇:Libgdx 游戏在 Android 上崩溃

                  相关文章

                  最新文章

                  <legend id='N7eMC'><style id='N7eMC'><dir id='N7eMC'><q id='N7eMC'></q></dir></style></legend>
                    1. <tfoot id='N7eMC'></tfoot>
                      • <bdo id='N7eMC'></bdo><ul id='N7eMC'></ul>

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

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