Wordwrap has lines too close together

When using manual WordWrap on OnScreenText, the new line is extremely close to the one above, and i don’t see a parameter to distance those lines.

Image :
text

I think that you can set the line-spacing in the font, either via the “setLineHeight” method or by passing in the “lineHeight” parameter to “loadFont”.

That said, have you perhaps set the point-size of the font here? As I myself found, doing so can produce the sort of overlapping that you’re seeing–and in the linked thread I was advised to instead use the “pixels-per-unit” setting.

1 Like

In fact, you have already been answered, but I can only offer an alternative API, it is more transparent.
OnScreenText and the rest of the classes are all endless wrappers of low-level classes. The problem is that they do not introduce anything fundamentally new or somehow simplify programming in practice.

from direct.showbase.ShowBase import ShowBase
from panda3d.core import TextNode, NodePath, DynamicTextFont

class Game(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        label = TextNode('label')
        label.set_font(DynamicTextFont('Roboto/Roboto-Italic.ttf'))
        label.font.set_line_height(1.5)
        label.set_wordwrap(10)

        label.set_text('Earth is the third planet from the Sun and the only place known in the universe where life has originated and found habitability.')

        label_node = NodePath(label.generate())
        label_node.set_scale(0.1)
        label_node.reparent_to(aspect2d)

game = Game()
game.run()
2 Likes