Phaser.js 中的阿拉伯语字体

Arabic font in Phaser.js

您好,我想在我的 Phaser 游戏中添加一些阿拉伯文字。我在 update() 函数中有以下内容:

    this.scoreText = this.add.text( this.world.centerX, this.world.height/5, 
                         "",{nsize: "32px", fill: "#FFF", align: "center"});

    this.scoreText.setText("تُفاحة");

这会在屏幕上生成非阿拉伯语的奇怪字母。有什么想法吗?

首先,您不应该在 update() 方法中 添加 文本 - 这会导致它被多次添加(最好是每帧一次每秒 60 次)。将其移至 create() 方法,以便只添加一次。您在参数中也有错字:nsize 应该只是 size.

function create() {
    this.scoreText = this.add.text( this.world.centerX, this.world.height / 5, "", { size: "32px", fill: "#FFF", align: "center" });
    this.scoreText.setText("تُفاحة");
}

你可以试试

将CSS部分的字体导入index.html

@import url(https://fonts.googleapis.com/earlyaccess/amiri.css);

然后只需将样式声明为变量

var style = { font: "32px Amiri", fill: "#333", align: "center" };

然后在 create 函数中添加类似 jsfiddle 中的文本 https://jsfiddle.net/albator2018/r2zLtoqd/

还有另一种方法可以做到这一点,但就像我刚才解释的那样,它工作正常