Skip to content

Commit bacfae1

Browse files
authored
Merge pull request #6623 from rexrainbow/bitmaptext-displayWidth,displayHeight
Add setDisplaySize method in BitmapText
2 parents bedf81a + 7f68277 commit bacfae1

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/gameobjects/bitmaptext/static/BitmapText.js

+50
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,34 @@ var BitmapText = new Class({
852852
return this;
853853
},
854854

855+
/**
856+
* Sets the display size of this BitmapText Game Object.
857+
*
858+
* Calling this will adjust the scale.
859+
*
860+
* @method Phaser.GameObjects.BitmapText#setDisplaySize
861+
* @since 3.61.0
862+
*
863+
* @param {number} width - The width of this BitmapText Game Object.
864+
* @param {number} height - The height of this BitmapText Game Object.
865+
*
866+
* @return {this} This Game Object instance.
867+
*/
868+
setDisplaySize: function (displayWidth, displayHeight)
869+
{
870+
this.setScale(1, 1);
871+
872+
this.getTextBounds(false);
873+
874+
var scaleX = displayWidth / this.width;
875+
876+
var scaleY = displayHeight / this.height;
877+
878+
this.setScale(scaleX, scaleY);
879+
880+
return this;
881+
},
882+
855883
/**
856884
* Controls the alignment of each line of text in this BitmapText object.
857885
*
@@ -1069,6 +1097,17 @@ var BitmapText = new Class({
10691097
*/
10701098
displayWidth: {
10711099

1100+
set: function(value)
1101+
{
1102+
this.setScaleX(1);
1103+
1104+
this.getTextBounds(false);
1105+
1106+
var scale = value / this.width;
1107+
1108+
this.setScaleX(scale);
1109+
},
1110+
10721111
get: function ()
10731112
{
10741113
return this.width;
@@ -1090,6 +1129,17 @@ var BitmapText = new Class({
10901129
*/
10911130
displayHeight: {
10921131

1132+
set: function(value)
1133+
{
1134+
this.setScaleY(1);
1135+
1136+
this.getTextBounds(false);
1137+
1138+
var scale = value / this.height;
1139+
1140+
this.setScaleY(scale);
1141+
},
1142+
10931143
get: function ()
10941144
{
10951145
return this.height;

0 commit comments

Comments
 (0)