As mentioned in a previous thread, I’m using TextNodes to display paragraphs of text.
As part of this, I place each TextNode-paragraph (save for the first of each page) beneath its predecessor, with an offset to space them out. This is based on the z-coordinate of the bottom of that predecessor, which in turn is calculated by subtracting the TextNode’s height (and a spacing constant) from it’s own z-coordinate.
Which brings me to my problem: every so often, I find a paragraph that’s further from its predecessor than expected.
Thinking that perhaps there were trailing “\n”-characters in some paragraphs, I printed out the result of “TextNode.getWordWrappedText()” for each paragraph, converted to a “bytes” object to . There weren’t any trailing “\n”-characters–but I was surprised to find that the locations of the “\n”-characters that were there didn’t match the line-breaks on-screen!
And indeed, I’m guessing that this is the source of my problem: that every so often the TextNode ends up with one more line than is shown on-screen, due to discrepancies in the line-breaking, and so ends up with a reported height that is greater than its on-screen height!
Cropped paragraph of text, as shown in-game:
Note that there are three lines of text.
Debug printings of “getWordwrappedText” and “getNumRows”, followed by the resultant output. The object named “entry” holds the TextNode that represents the paragraph in question.
print (bytes(entry.textNode.getWordwrappedText(), "utf-8")) print (entry.textNode.getNumRows())
b'In the lower districts of Tenereth in\nthose days, literacy was all but\nunknown. Who had the money to\nlearn?' 4
Note the number of lines, and the difference in the position of the final line-break.
I don’t think that I’m modifying these TextNodes in any way that seems likely to have an effect here.