Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New line '\n' generates invalid characters, and text is not properly aligned #124

Open
criistii opened this issue Sep 7, 2012 · 1 comment

Comments

@criistii
Copy link

criistii commented Sep 7, 2012

When creating a text like "Some\nText", the text is properly split into 2 lines, however, the second line has a strange character before it.

If Aligned to the left, it looks like this:
Some
þText

@criistii
Copy link
Author

criistii commented Sep 8, 2012

I think I fixed the bug, if anyone could update the code here, that would be great:

In the UIText class, in the drawText method (somewhere around line 250), make sure you add a new line validation when adding characters:

        // Extend end of line
        lineEndChar = i;

        if( charId != ASCII_NEWLINE )
        {
            // add quads for each char
            // Use curpos instead of i to compensate for line wrapping hyphenation
            // reuse a UISprite if we have one. if we don't, we need to set it's parent and add it to the textInstance's list
            var currentTextSprite = textInstance.textSpriteAtIndex( i );
            var addingNewTextSprite = currentTextSprite == null;

            currentTextSprite = configureSpriteForCharId( currentTextSprite, charId, dx, dy, scale, 0 );

            if( addingNewTextSprite )
            {
                currentTextSprite.color = color.Length == 1 ? color[0] : color[i];
                currentTextSprite.parentUIObject = textInstance;
                textInstance.textSprites.Add( currentTextSprite );
            }

            // Ensure the sprite is hidden if the textInstance is
            currentTextSprite.hidden = hidden;

            // See below @NOTE re: offsetx vs. xadvance bugfix.
            // advance the position to draw the next letter
            dx += _fontDetails[charId].xadvance * scale;
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant