如何让 wordWrap 在 PIXIjs BitmapText 中工作

How to get wordWrap to work in PIXIjs BitmapText

Objective

我们正在尝试让 wordWrap 与 PIXIjs (v3) PIXI.extras.BitmapText 一起工作,但我们无法让它以与标准文本相同的方式工作。

期望的输出: [按预期换行]

var someText = new window.PIXI.Text('blah blah blah',
                {
                    font: '32px Arial',
                    fill: 0x939393,
                    align: 'center',
                    wordWrap: true,
                    wordWrapWidth: me.width * (0.9 / window.devicePixelRatio)
                });

问题: [没有按预期换行]

var someOtherText = new window.PIXI.BitmapText('blah blah blah',
                {
                    font: 'santana-grey-20',
                    align: 'center',
                    wordWrap: true,
                    wordWrapWidth: me.width * (0.9 / window.devicePixelRatio)
                });

有没有人以前做过这个或者对尝试什么有什么建议?

与PIXI.Text不同,PIXI BitmapText 没有内置的自动换行支持。

您唯一的选择是将文本拆分为多个 PIXI 位图文本。

在位图文本中,您必须将样式的 maxWidth 属性 设置为换行符 见 here

var someOtherText = new window.PIXI.BitmapText('blah blah blah',
                {
                    font: 'santana-grey-20',
                    align: 'center',
                    maxWidth: 200
// The max width of the text before line wrapping.
                });