Skip to content

Commit 14ba51d

Browse files
committed
Added Text.setResolution methods.
1 parent 1b9f5dc commit 14ba51d

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### New Features
66

77
* `Camera.resolution` is a new read-only property that holds the current game config resolution that the camera is using. This is used internally for viewport calculations.
8+
* `Text.resolution` and the method `Text.setResolution` allows you to control the resolution of a Static Text Game Object. By default it will be set to match the resolution set in the Game Config, but you can override it yourself via the TextStyle. It allows for much clearer text on High DPI devices, at the cost of larger internal Canvas textures for the Text - so please use with caution, as the more high res Text you have, the more memory it uses up. Fix #3528 (thanks @kirillbunin)
89

910
### Updates
1011

src/gameobjects/text/TextStyle.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,29 @@ var TextStyle = new Class({
687687
return this.update(false);
688688
},
689689

690+
/**
691+
* Set the resolution used by the Text object.
692+
*
693+
* By default it will be set to match the resolution set in the Game Config,
694+
* but you can override it via this method. It allows for much clearer text on High DPI devices,
695+
* at the cost of memory because it uses larger internal Canvas textures for the Text.
696+
*
697+
* Please use with caution, as the more high res Text you have, the more memory it uses up.
698+
*
699+
* @method Phaser.GameObjects.Text.TextStyle#setResolution
700+
* @since 3.12.0
701+
*
702+
* @param {number} value - The resolution for this Text object to use.
703+
*
704+
* @return {Phaser.GameObjects.Text} The parent Text object.
705+
*/
706+
setResolution: function (value)
707+
{
708+
this.resolution = value;
709+
710+
return this.update(false);
711+
},
712+
690713
/**
691714
* Set the stroke settings.
692715
*

src/gameobjects/text/static/Text.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,29 @@ var Text = new Class({
853853
return this.style.setAlign(align);
854854
},
855855

856+
/**
857+
* Set the resolution used by this Text object.
858+
*
859+
* By default it will be set to match the resolution set in the Game Config,
860+
* but you can override it via this method, or by specifying it in the Text style configuration object.
861+
*
862+
* It allows for much clearer text on High DPI devices, at the cost of memory because it uses larger
863+
* internal Canvas textures for the Text.
864+
*
865+
* Therefore, please use with caution, as the more high res Text you have, the more memory it uses.
866+
*
867+
* @method Phaser.GameObjects.Text#setResolution
868+
* @since 3.12.0
869+
*
870+
* @param {number} value - The resolution for this Text object to use.
871+
*
872+
* @return {Phaser.GameObjects.Text} This Text object.
873+
*/
874+
setResolution: function (value)
875+
{
876+
return this.style.setResolution(value);
877+
},
878+
856879
/**
857880
* Set the text padding.
858881
*

0 commit comments

Comments
 (0)