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

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

    2. <tfoot id='D6TW4'></tfoot>
    3. <small id='D6TW4'></small><noframes id='D6TW4'>

    4. (Libgdx 1.6.1) BitmapFontCache.draw 由于索引超出范围而

      时间:2023-05-20
        <tbody id='qTOwb'></tbody>
        • <legend id='qTOwb'><style id='qTOwb'><dir id='qTOwb'><q id='qTOwb'></q></dir></style></legend>

            <tfoot id='qTOwb'></tfoot>

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

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

                本文介绍了(Libgdx 1.6.1) BitmapFontCache.draw 由于索引超出范围而崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我最近刚刚将我的 Libgdx 项目从 1.4.x 更新到 1.6.1.我在游戏中使用 BitmapFontCache 进行对话,使用 BitmapFontCache.draw(start, end) 逐个字符地绘制字符串.这在 1.4.x 中运行良好,但在进行必要的更改以构建 1.6.1 后,在显示最后一个字符后启用换行时似乎会导致崩溃.奇怪的是,这似乎不是单行字符串的问题.

                I just recently updated my Libgdx project from 1.4.x to 1.6.1. I use BitmapFontCache for my dialogue in my game, drawing a string character by character using BitmapFontCache.draw(start, end). This was working fine in 1.4.x but after making the necessary changes to get 1.6.1 to build, it seems to cause a crash when wrapping is enabled after the last character is displayed. Strangely this does not seem to be a problem with one line strings.

                这是我添加文本的方式:

                Here is how I add my text:

                fontCache.addText( message, fontPosX, fontPosY, fontWidth, Align.left, true);
                

                然后我增加字符数并绘制.currentCharacter 根据其长度到达字符串末尾时停止:

                Then I increment the character count and draw. currentCharacter stops when reaching the end of the string based on its length:

                fontCache.draw( batch, 0, currentCharacter );
                

                这在 1.4.x 中运行良好,即使使用多行包装的字符串,但如果行换行到第二行(绘制最后一个字符后崩溃)似乎会导致越界异常.这是导致 SpriteBatch 崩溃的行.

                This worked fine in 1.4.x even with multi-line wrapped strings but seems to cause an out of bounds exception if the lines wraps to a second line (crashes after drawing the last character). Here is the line causing crash in SpriteBatch.

                System.arraycopy(spriteVertices, offset, vertices, idx, copyCount);
                

                我需要一种新的方法来计算用于绘制的字符串的长度吗?我需要以某种方式使用返回的 GlyphLayout 吗?或者这可能是一个错误?

                Is there a new way I need to be calculating the length of the string for drawing? Do I need to use the return GlyphLayout in some way? Or is this perhaps a bug?

                推荐答案

                好的,我知道问题出在哪里,而且我很确定这是 libgdx 中的一个错误.

                OK, I know where the issue lies, and I'm pretty certain it's a bug in libgdx.

                我也有一个解决方法,虽然它有点 hacky.

                I also have a workaround, although it's a little hacky.

                问题GlyphLayout 在空格字符上换行时,它会优化终止空格.因此,删除空格后,布局中的字形总数现在少于字符串中的字符数.包裹在空格字符上的行越多,两者之间的差异就越大.

                The Problem When GlyphLayout wraps a line on a space character, it optimises out the terminating space. So with the space removed, the total number of glyphs in the layout is now less than the number of characters in the string. The more lines that get wrapped on a space character, the bigger the discrepency will be between the two.

                解决方法因此,为了计算出渲染全文使用的长度,我们需要计算 GlyphLayout 中的字形数量,而不是 String 中的字符数量.这里有一些代码可以做到这一点......

                The Workaround In order to work out what length to use for rendering the full text therefore, we need to count the number of glyphs in the GlyphLayout instead of the number of characters in the String. Here's some code that does that...

                private int calcLength(GlyphLayout glyphLayout) {
                
                    int length = 0;
                    for(GlyphLayout.GlyphRun run : glyphLayout.runs) {
                        length += run.glyphs.size;
                    }
                    return length;
                }
                

                要传入的 GlyphLayout 将是 BitmapFontCache.addText() 方法返回的那个.

                The GlyphLayout to pass in will be the one that was returned by the BitmapFontCache.addText() method.

                这篇关于(Libgdx 1.6.1) BitmapFontCache.draw 由于索引超出范围而崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:libgdx Json 解析 下一篇:滑块在表格中始终具有默认宽度

                相关文章

                最新文章

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

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

                2. <small id='Ydurm'></small><noframes id='Ydurm'>

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