Skip to content

Commit 114b7b5

Browse files
authored
Merge pull request phaserjs#4552 from rexrainbow/master
Set canvas size equal to text object size
2 parents 5b85cd4 + 9a95863 commit 114b7b5

3 files changed

Lines changed: 19 additions & 19 deletions

File tree

src/gameobjects/text/static/Text.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ var Text = new Class({
185185
* @private
186186
* @since 3.12.0
187187
*/
188-
this._text = '';
188+
this._text = undefined;
189189

190190
/**
191191
* Specify a padding value which is added to the line width and height when calculating the Text size.
@@ -1118,36 +1118,34 @@ var Text = new Class({
11181118

11191119
var padding = this.padding;
11201120

1121-
var w = textSize.width + padding.left + padding.right;
1122-
var h = textSize.height + padding.top + padding.bottom;
1121+
var textWidth;
11231122

11241123
if (style.fixedWidth === 0)
11251124
{
1126-
this.width = w;
1125+
this.width = textSize.width + padding.left + padding.right;
1126+
textWidth = textSize.width;
11271127
}
11281128
else
11291129
{
11301130
this.width = style.fixedWidth;
1131+
textWidth = this.width - padding.left - padding.right;
1132+
if (textWidth < textSize.width)
1133+
{
1134+
textWidth = textSize.width;
1135+
}
11311136
}
11321137

11331138
if (style.fixedHeight === 0)
11341139
{
1135-
this.height = h;
1140+
this.height = textSize.height + padding.top + padding.bottom;
11361141
}
11371142
else
11381143
{
11391144
this.height = style.fixedHeight;
11401145
}
11411146

1142-
if (w > this.width)
1143-
{
1144-
w = this.width;
1145-
}
1146-
1147-
if (h > this.height)
1148-
{
1149-
h = this.height;
1150-
}
1147+
var w = this.width;
1148+
var h = this.height;
11511149

11521150
this.updateDisplayOrigin();
11531151

@@ -1208,11 +1206,11 @@ var Text = new Class({
12081206
}
12091207
else if (style.align === 'right')
12101208
{
1211-
linePositionX += textSize.width - textSize.lineWidths[i];
1209+
linePositionX += textWidth - textSize.lineWidths[i];
12121210
}
12131211
else if (style.align === 'center')
12141212
{
1215-
linePositionX += (textSize.width - textSize.lineWidths[i]) / 2;
1213+
linePositionX += (textWidth - textSize.lineWidths[i]) / 2;
12161214
}
12171215

12181216
if (this.autoRound)

src/gameobjects/text/static/TextCanvasRenderer.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
*/
2222
var TextCanvasRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix)
2323
{
24-
if (src.text !== '')
24+
if ((src.width === 0) || (src.height === 0))
2525
{
26-
renderer.batchSprite(src, src.frame, camera, parentMatrix);
26+
return;
2727
}
28+
29+
renderer.batchSprite(src, src.frame, camera, parentMatrix);
2830
};
2931

3032
module.exports = TextCanvasRenderer;

src/gameobjects/text/static/TextWebGLRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var Utils = require('../../../renderer/webgl/Utils');
2323
*/
2424
var TextWebGLRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix)
2525
{
26-
if (src.text === '')
26+
if ((src.width === 0) || (src.height === 0))
2727
{
2828
return;
2929
}

0 commit comments

Comments
 (0)