Closed JanusSpark closed 4 years ago
I can add a new callback, e.g.,
var text = this.advancedWordWrapCallback(text);
But for more complex needs maybe it's simpler to just let users overwrite the method, like you did.
Or does your change keep the existing behavior too? You could make a PR then.
This is my solution, just add space by sprite width and fontsize .
// add space ecah n characters
function chunk(str, n) {
var result = [];
for(i = 0; i < str.length; i += n) {
result.push(str.substr(i, n))
}
return result
};
function formatChinese(text, sprite) {
var fontSize = text.fontSize
var lineWidth = sprite.width
var context = text.text
var wrapWidth = Math.floor(lineWidth / fontSize)
text.setText(chunk(context, wrapWidth).join(' '))
}
My English isn't good. If you can't understand this. I'm so sorry about that; You can find the the notes with modification with ctrl+f and find 'Chinese'
when I create Phaser.Text like this with Chinese
var text = ‘’参与《啦啦啦啦》小游戏免费领福利啦!Have a good time'; var desc = new Phaser.Text(game, 0, 0, text, {font: 'normal 32px', fill: '#425572', wordWrap: true, wordWrapWidth: 488});
You need to know there is no space during Chinese words so the wordWrap didn't work at all; So I have to fixed the advancedWrap function like this
`Phaser.Text.prototype.advancedWordWrap = function (text) {
};`
And then I can use the wordWrap In Chinese with these code
desc.useAdvancedWrap = true; desc.updateText();