Add setDisplaySize method

This commit is contained in:
Rex 2023-09-17 10:37:35 +08:00
parent cbb802bcff
commit 2241671a61

View file

@ -855,6 +855,34 @@ var BitmapText = new Class({
return this;
},
/**
* Sets the display size of this BitmapText Game Object.
*
* Calling this will adjust the scale.
*
* @method Phaser.GameObjects.Components.Size#setDisplaySize
* @since 3.61.0
*
* @param {number} width - The width of this BitmapText Game Object.
* @param {number} height - The height of this BitmapText Game Object.
*
* @return {this} This Game Object instance.
*/
setDisplaySize: function (displayWidth, displayHeight)
{
this.setScale(1, 1);
this.getTextBounds(false);
var scaleX = displayWidth / this.width;
var scaleY = displayHeight / this.height;
this.setScale(scaleX, scaleY);
return this;
},
/**
* Controls the alignment of each line of text in this BitmapText object.
*
@ -1072,6 +1100,17 @@ var BitmapText = new Class({
*/
displayWidth: {
set: function(value)
{
this.setScaleX(1);
this.getTextBounds(false);
var scale = value / this.width;
this.setScaleX(scale);
},
get: function ()
{
return this.width;
@ -1093,6 +1132,17 @@ var BitmapText = new Class({
*/
displayHeight: {
set: function(value)
{
this.setScaleY(1);
this.getTextBounds(false);
var scale = value / this.height;
this.setScaleY(scale);
},
get: function ()
{
return this.height;