Skip to content

Commit 00929a0

Browse files
authored
Merge pull request phaserjs#3480 from wtravO/FR3472
Feature Request phaserjs#3472
2 parents 67c0bb8 + af12eaa commit 00929a0

5 files changed

Lines changed: 20 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ being passed to the simulation. The default value is 1 to remain consistent with
1919
* HTML5AudioSound.setVolume is a chainable way to set the volume of a single Sound instance.
2020
* HTML5AudioSound.setSeek is a chainable way to set seek to a point of a single Sound instance.
2121
* HTML5AudioSound.setLoop is a chainable way to set the loop state of a single Sound instance.
22+
* BitmapText has a new property `letterSpacing` which accepts a positive or negative number to add / reduce spacing between characters (thanks @wtravO)
2223
* Matter Physics has two new debug properties: `debugShowJoint` and `debugJointColor`. If defined they will display joints in Matter bodies during the postUpdate debug phase (only if debug is enabled) (thanks @OmarShehata)
2324
* You can now pass a Sprite Sheet or Canvas as the Texture key to `Tilemap.addTileset` and it will work in WebGL, where-as before it would display a corrupted tilemap. Fix #3407 (thanks @Zykino)
2425
* Graphics.slice allows you to easily draw a Pacman, or slice of pie shape to a Graphics object.

src/gameobjects/bitmaptext/GetBitmapTextSize.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var GetBitmapTextSize = function (src, round)
2626

2727
var chars = src.fontData.chars;
2828
var lineHeight = src.fontData.lineHeight;
29+
var letterSpacing = src.letterSpacing;
2930

3031
var xAdvance = 0;
3132
var yAdvance = 0;
@@ -98,7 +99,7 @@ var GetBitmapTextSize = function (src, round)
9899
bh = gh;
99100
}
100101

101-
xAdvance += glyph.xAdvance;
102+
xAdvance += glyph.xAdvance + letterSpacing;
102103
indexCount += 1;
103104
lastGlyph = glyph;
104105
lastCharCode = charCode;

src/gameobjects/bitmaptext/static/BitmapText.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var Render = require('./BitmapTextRender');
3333
* @property {string} font - [description]
3434
* @property {string} text - [description]
3535
* @property {number} fontSize - [description]
36+
* @property {number} letterSpacing - Adds/Removes spacing between characters
3637
*/
3738

3839
/**
@@ -129,6 +130,16 @@ var BitmapText = new Class({
129130
*/
130131
this.fontSize = size || this.fontData.size;
131132

133+
/**
134+
* Adds/Removes spacing between characters
135+
* Can be a negative or positive number
136+
*
137+
* @name Phaser.GameObjects.BitmapText#letterSpacing
138+
* @type {number}
139+
* @since 3.4.0
140+
*/
141+
this.letterSpacing = 0;
142+
132143
this.setTexture(entry.texture, entry.frame);
133144
this.setPosition(x, y);
134145
this.setOrigin(0, 0);

src/gameobjects/bitmaptext/static/BitmapTextCanvasRenderer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage,
3434

3535
var chars = src.fontData.chars;
3636
var lineHeight = src.fontData.lineHeight;
37+
var letterSpacing = src.letterSpacing;
3738

3839
var xAdvance = 0;
3940
var yAdvance = 0;
@@ -140,7 +141,7 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage,
140141
x *= scale;
141142
y *= scale;
142143

143-
xAdvance += glyph.xAdvance;
144+
xAdvance += glyph.xAdvance + letterSpacing;
144145
indexCount += 1;
145146
lastGlyph = glyph;
146147
lastCharCode = charCode;

src/renderer/webgl/pipelines/TextureTintPipeline.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,7 @@ var TextureTintPipeline = new Class({
946946
var rotation = -bitmapText.rotation;
947947
var scaleX = bitmapText.scaleX;
948948
var scaleY = bitmapText.scaleY;
949+
var letterSpacing = bitmapText.letterSpacing;
949950
var sr = Math.sin(rotation);
950951
var cr = Math.cos(rotation);
951952
var sra = cr * scaleX;
@@ -1005,7 +1006,7 @@ var TextureTintPipeline = new Class({
10051006
x += (kerningOffset !== undefined) ? kerningOffset : 0;
10061007
}
10071008

1008-
xAdvance += glyph.xAdvance;
1009+
xAdvance += glyph.xAdvance + letterSpacing;
10091010
indexCount += 1;
10101011
lastGlyph = glyph;
10111012
lastCharCode = charCode;
@@ -1178,6 +1179,7 @@ var TextureTintPipeline = new Class({
11781179
var rotation = -bitmapText.rotation;
11791180
var scaleX = bitmapText.scaleX;
11801181
var scaleY = bitmapText.scaleY;
1182+
var letterSpacing = bitmapText.letterSpacing;
11811183
var sr = Math.sin(rotation);
11821184
var cr = Math.cos(rotation);
11831185
var sra = cr * scaleX;
@@ -1252,7 +1254,7 @@ var TextureTintPipeline = new Class({
12521254
x += (kerningOffset !== undefined) ? kerningOffset : 0;
12531255
}
12541256

1255-
xAdvance += glyph.xAdvance;
1257+
xAdvance += glyph.xAdvance + letterSpacing;
12561258
indexCount += 1;
12571259
lastGlyph = glyph;
12581260
lastCharCode = charCode;

0 commit comments

Comments
 (0)