Skip to content

Commit d23e5d6

Browse files
committed
BitmapText.smoothed is a new boolean property that allows you to set texture smoothing on a bitmap font or not. By default smoothing is always on, but you can turn it off which helps for bitmap fonts created from pixel art style character sets.
1 parent 159f49d commit d23e5d6

4 files changed

Lines changed: 36 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ If you are an exceptional JavaScript developer and would like to join the Phaser
252252

253253
* Loader.images is a new method that allows you to pass an array of image keys, and optionally the urls, to the Loader and have them all added to the load queue in one go.
254254
* Tween.frameBased allows you to control if a Tween updates based on the physics step (i.e. frame based) or the system clock (time based). A frame based tween will use the physics elapsed timer when updating. This means it will retain the same consistent frame rate, regardless of the speed of the device. The duration value given should be given in frames. If the Tween uses a time based update (which is the default) then the duration is given in milliseconds. In this situation a 2000ms tween will last exactly 2 seconds, regardless of the device and how many visual updates the tween has actually been through.
255+
* BitmapText.smoothed is a new boolean property that allows you to set texture smoothing on a bitmap font or not. By default smoothing is always on, but you can turn it off which helps for bitmap fonts created from pixel art style character sets.
255256

256257
### Updates
257258

src/gameobjects/BitmapText.js

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,16 +375,13 @@ Phaser.BitmapText.prototype.updateText = function () {
375375
{
376376
// Sprite already exists in the glyphs pool, so we'll reuse it for this letter
377377
g.texture = charData.texture;
378-
// g.name = line.text[c];
379-
// console.log('reusing', g.name, 'as', line.text[c]);
380378
}
381379
else
382380
{
383381
// We need a new sprite as the pool is empty or exhausted
384382
g = new PIXI.Sprite(charData.texture);
385383
g.name = line.text[c];
386384
this._glyphs.push(g);
387-
// console.log('new', line.text[c]);
388385
}
389386

390387
g.position.x = (line.chars[c] + align) - ax;
@@ -613,3 +610,36 @@ Object.defineProperty(Phaser.BitmapText.prototype, 'maxWidth', {
613610
}
614611

615612
});
613+
614+
/**
615+
* Enable or disable texture smoothing for this BitmapText.
616+
*
617+
* The smoothing is applied to the BaseTexture of this font, which all letters of the text reference.
618+
*
619+
* Smoothing is enabled by default.
620+
*
621+
* @name Phaser.BitmapText#smoothed
622+
* @property {boolean} smoothed
623+
*/
624+
Object.defineProperty(Phaser.BitmapText.prototype, 'smoothed', {
625+
626+
get: function() {
627+
628+
return !this._data.base.scaleMode;
629+
630+
},
631+
632+
set: function(value) {
633+
634+
if (value)
635+
{
636+
this._data.base.scaleMode = 0;
637+
}
638+
else
639+
{
640+
this._data.base.scaleMode = 1;
641+
}
642+
643+
}
644+
645+
});

src/loader/Loader.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,7 @@ Phaser.Loader.prototype = {
12931293
* @return {Phaser.Loader} This Loader instance.
12941294
*/
12951295
bitmapFont: function (key, textureURL, atlasURL, atlasData, xSpacing, ySpacing) {
1296+
12961297
if (textureURL === undefined || textureURL === null)
12971298
{
12981299
textureURL = key + '.png';

typescript/phaser.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ declare module Phaser {
328328
renderOrderID: number;
329329
right: number;
330330
text: string;
331+
smoothed: boolean;
331332
textWidth: number;
332333
textHeight: number;
333334
tint: number;

0 commit comments

Comments
 (0)