Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setDisplaySize method in BitmapText #6623

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/gameobjects/bitmaptext/static/BitmapText.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.BitmapText#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.
*
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down