<legend id='0yrnc'><style id='0yrnc'><dir id='0yrnc'><q id='0yrnc'></q></dir></style></legend>
      <tfoot id='0yrnc'></tfoot>
        <bdo id='0yrnc'></bdo><ul id='0yrnc'></ul>

      <small id='0yrnc'></small><noframes id='0yrnc'>

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

      1. 如何在 LibGDX 中绘制 BitmapFont?

        时间:2023-05-20

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

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

            1. <legend id='oejGP'><style id='oejGP'><dir id='oejGP'><q id='oejGP'></q></dir></style></legend>

                <tfoot id='oejGP'></tfoot>

                  <tbody id='oejGP'></tbody>
                  <bdo id='oejGP'></bdo><ul id='oejGP'></ul>
                  本文介绍了如何在 LibGDX 中绘制 BitmapFont?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我敢打赌,我做了一些愚蠢的事情,只是似乎没有注意到它.

                  I'm seriously betting that I did something effing stupid and just can't seem to notice it.

                  package com.me.mygdxgame;
                  
                  import com.badlogic.gdx.ApplicationListener;
                  import com.badlogic.gdx.Gdx;
                  import com.badlogic.gdx.graphics.GL10;
                  import com.badlogic.gdx.graphics.OrthographicCamera;
                  import com.badlogic.gdx.graphics.Texture;
                  import com.badlogic.gdx.graphics.Texture.TextureFilter;
                  import com.badlogic.gdx.graphics.g2d.BitmapFont;
                  import com.badlogic.gdx.graphics.g2d.Sprite;
                  import com.badlogic.gdx.graphics.g2d.SpriteBatch;
                  import com.badlogic.gdx.graphics.g2d.TextureRegion;
                  
                  public class Locked implements ApplicationListener
                  {
                      private OrthographicCamera camera;
                      private SpriteBatch batch;
                      private Texture texture;
                      private Sprite sprite;
                      private BitmapFont font;
                      private CharSequence str = "Hello World!";
                      private float width;
                      private float height;
                  
                      @Override
                      public void create()
                      {
                          width = Gdx.graphics.getWidth();
                          height = Gdx.graphics.getHeight();
                  
                          camera = new OrthographicCamera(1, height / width);
                          batch = new SpriteBatch();
                  
                          texture = new Texture(Gdx.files.internal("data/libgdx.png"));
                          texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
                  
                          TextureRegion region = new TextureRegion(texture, 0, 0, 512, 275);
                  
                          sprite = new Sprite(region);
                          sprite.setSize(0.9f, 0.9f * sprite.getHeight() / sprite.getWidth());
                          sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2);
                          sprite.setPosition(-sprite.getWidth() / 2, -sprite.getHeight() / 2);
                  
                          font = new BitmapFont(Gdx.files.internal("data/digib.fnt"),
                                  Gdx.files.internal("data/digib.png"), false);
                      }
                  
                      @Override
                      public void dispose()
                      {
                          batch.dispose();
                          texture.dispose();
                      }
                  
                      @Override
                      public void render()
                      {
                          Gdx.gl.glClearColor(1, 1, 1, 1);
                          Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
                  
                          batch.setProjectionMatrix(camera.combined);
                          batch.begin();
                          font.setColor(0.0f, 0.0f, 0.0f, 1.0f);
                  
                          //sprite.draw(batch);
                          font.draw(batch, str, width*0.5f, height*0.5f);
                          batch.end();
                      }
                  
                      @Override
                      public void resize(int width, int height)
                      {
                      }
                  
                      @Override
                      public void pause()
                      {
                      }
                  
                      @Override
                      public void resume()
                      {
                      }
                  }
                  

                  项目是使用他们提供的模板工具生成的gdx-setup-ui.jar正如您在代码中看到的那样,我没有费心摆脱默认代码(只是一些简单的绘制代码来呈现 LibGDX 徽标).

                  The project was generated with the template tool they provide gdx-setup-ui.jar As you can see in the code, I didn't bother to get rid of the default codes (Just some simple draw codes to render the LibGDX logo).

                  因此,对于干净生成的项目,我在此处遵循本指南http://code.google.com/p/libgdx-users/wiki/addingText2D

                  So, with the cleanly generated project, I followed this guide here http://code.google.com/p/libgdx-users/wiki/addingText2D

                  最后得到上面提供的代码.

                  and finally arriving with the provided code above.

                  问题是,为什么 !@#$ing 文本不显示!?我换了很多次位置,仍然没有运气:

                  The problem is, why won't the !@#$ing text show!? I changed the position so many times and still no luck :

                  我错过了什么吗?

                  仅供参考:字体很好,我将它们放到另一个游戏中,它可以工作.

                  FYI: The fonts are fine, I dropped them into another game and it works.

                  推荐答案

                  尝试像这样改变投影矩阵:

                  Try to change projection matrix like this:

                  Matrix4 normalProjection = new Matrix4().setToOrtho2D(0, 0, Gdx.graphics.getWidth(),  Gdx.graphics.getHeight());
                  
                  batch.setProjectionMatrix(normalProjection);
                  

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

                  上一篇:IntelliJ 找不到任何 LibGDX 包? 下一篇:libgdx 纹理过滤器和 mipmap

                  相关文章

                  最新文章

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

                      <legend id='qYST3'><style id='qYST3'><dir id='qYST3'><q id='qYST3'></q></dir></style></legend>
                      <tfoot id='qYST3'></tfoot>

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