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

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

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

      1. 使用 libgdx 在运行时生成带有文本的纹理

        时间:2023-05-19

            <tfoot id='1v3ik'></tfoot>

              <bdo id='1v3ik'></bdo><ul id='1v3ik'></ul>
            • <small id='1v3ik'></small><noframes id='1v3ik'>

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

                  本文介绍了使用 libgdx 在运行时生成带有文本的纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在开发一个电话文字游戏.昨天我决定使用 libgdx 切换到 OpenGL,以尝试提高图形性能和电池使用率 + 以针对更多平台.

                  I'm working on a phone word game. Yesterday I decided to switch to OpenGL using libgdx to try and improve graphics performance and battery usage + to target more platforms.

                  在 2D 画布上绘制字母拼贴的方式是每个字母拼贴都会为自己创建一个位图.我会:

                  The way letter tile drawing was working on a 2D canvas was each letter tile would create a bitmap for itself. I would:

                  1. 从背景位图创建一个新的可变位图.
                  2. 在新位图上画出字母.
                  3. 应用其他磁贴特定效果.
                  4. 为每一帧绘制新的位图

                  使用 libgdx 实现我想要的最佳方式是什么?

                  What's the best way for me to achieve what I want using libgdx?

                  1. 我应该采用类似的方法吗?如果是这样,怎么做?我尝试使用像素图,但不知道如何绘制字体.
                  2. 我是否应该使用 A-Z 中所有必需的图块创建一个 spritesheet 并直接使用它?调整平铺背景的设计时有点乏味.
                  3. 我应该做一些完全不同的事情吗?

                  回答

                  显然,最终代码不应该每次都从文件中加载,因为这会对性能造成巨大影响,但这里是为尝试获得相同结果的其他人提供的工作示例代码.

                  Answer

                  Obviously the final code shouldn't load from the files every time, as this is a massive performance hit, but here's working sample code for anyone else who is trying to achieve the same result.

                      // load the background into a pixmap
                      Pixmap tile = new Pixmap(Gdx.files.getFileHandle(
                              "someFile.png", FileType.Internal));
                  
                      // load the font
                      FileHandle handle = Gdx.files.getFileHandle("someFont.fnt",
                              FileType.Internal);
                      BitmapFont font = new BitmapFont(handle);
                  
                      // get the glypth info
                      BitmapFontData data = font.getData();
                      Pixmap fontPixmap = new Pixmap(Gdx.files.internal(data.imagePaths[0]));
                      Glyph glyph = data.getGlyph(getLetterToDraw().charAt(0));
                  
                      // draw the character onto our base pixmap
                      tile.drawPixmap(fontPixmap, (TILE_WIDTH - glyph.width) / 2, (TILE_HEIGHT - glyph.height) / 2,
                              glyph.srcX, glyph.srcY, glyph.width, glyph.height);
                  
                      // save this as a new texture
                      texture = new Texture(tile);
                  

                  推荐答案

                  引用:你可以创建一个 BitmapFontData 实例并使用 BitmapFontData.getImagePath() 加载一个 Pixmap 包含 glyphs.然后,您可以使用 BitmapFontData.getGlyph 来获取 Pixmap 中特定字形的位置,您可以将其与 Pixmap.drawPixmap() 一起使用做你想做的事.来源:libgdx 第 691 期:将 BitmapFont 绘制到 Pixmap/Texture

                  Quote: You can create a BitmapFontData instance and use BitmapFontData.getImagePath() to load a Pixmap containing the glyphs. You can then use BitmapFontData.getGlyph to get the location of a specific glyph in the Pixmap, which you can use with Pixmap.drawPixmap() to do what you want to do. Source: libgdx Issue 691: Draw BitmapFont to Pixmap/Texture

                  您获得 BitmapFontData 的路径并使用该路径的 Filehandle 创建一个新的 Pixmap:

                  You get the path to the BitmapFontData and create a new Pixmap with the Filehandle to the path with this:

                  像素图(文件句柄文件)

                  Pixmap(FileHandle file)

                  从给定文件创建一个新的像素图实例.

                  Creates a new Pixmap instance from the given file.

                  来源:PixmapAPI

                  使用 Gdx.files.internal(pathfromBitmapFontData)作为文件句柄,你就得到了包含所有 Glyps 的像素图.

                  Use Gdx.files.internal(pathfromBitmapFontData)as filehandle and you got the pixmap with all Glyps inside.

                  Pixmap p = new Pixmap(Gdx.files.internal(myBitmapFontData.getImagePath()))

                  试试它是否是内部的!可能不是我不知道的内部文件

                  Pixmap p = new Pixmap(myFont.getData().getFontFile());

                  这也应该有效

                  这篇关于使用 libgdx 在运行时生成带有文本的纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:FitViewport 中的 LibGDX 背景图像 下一篇:将 LibGDX 与 Android 首选项一起使用

                  相关文章

                  最新文章

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

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

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

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