Skip to content

Commit d1b3164

Browse files
committed
Fix text align to right/center issue
Calculate text-width in fixedWidth mode
1 parent 97b60ef commit d1b3164

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/gameobjects/text/static/Text.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,13 +1118,20 @@ var Text = new Class({
11181118

11191119
var padding = this.padding;
11201120

1121+
var textWidth;
1122+
11211123
if (style.fixedWidth === 0)
11221124
{
11231125
this.width = textSize.width + padding.left + padding.right;
1126+
textWidth = textSize.width;
11241127
}
11251128
else
11261129
{
11271130
this.width = style.fixedWidth;
1131+
textWidth = this.width - padding.left - padding.right;
1132+
if (textWidth < textSize.width) {
1133+
textWidth = textSize.width;
1134+
}
11281135
}
11291136

11301137
if (style.fixedHeight === 0)
@@ -1198,11 +1205,11 @@ var Text = new Class({
11981205
}
11991206
else if (style.align === 'right')
12001207
{
1201-
linePositionX += textSize.width - textSize.lineWidths[i];
1208+
linePositionX += textWidth - textSize.lineWidths[i];
12021209
}
12031210
else if (style.align === 'center')
12041211
{
1205-
linePositionX += (textSize.width - textSize.lineWidths[i]) / 2;
1212+
linePositionX += (textWidth - textSize.lineWidths[i]) / 2;
12061213
}
12071214

12081215
if (this.autoRound)

0 commit comments

Comments
 (0)