瀏覽代碼

feature: game.add.text now accepts paragraphs

lairaalmas 1 年之前
父節點
當前提交
10c7cb8c10
共有 1 個文件被更改,包括 6 次插入1 次删除
  1. 6 1
      src/js/gameMechanics.js

+ 6 - 1
src/js/gameMechanics.js

@@ -933,7 +933,12 @@ const game = {
       context.textAlign = cur.align;
       context.fillStyle = cur.fill;
       // Text
-      context.fillText(cur.name, x, y);
+      const paragraphs = String(cur.name).split('\n');
+      let newY = y;
+      for (let line in paragraphs) {
+        context.fillText(paragraphs[line], x, newY);
+        newY += 48;
+      }
       // End
       context.shadowBlur = 0;
       context.globalAlpha = 1;