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

Changing text property of tinted BitmapText doesn't use correct glyphs #1969

Closed
Pajamaman opened this issue Aug 2, 2015 · 8 comments
Closed

Comments

@Pajamaman
Copy link

Add a BitmapText to the game and give it a tint:

var game = new Phaser.Game(320, 200, Phaser.AUTO, '', {preload: preload, create: create}),
    text;

function preload() {
    game.load.bitmapFont('desyrel', 'desyrel.png', 'desyrel.xml');
}

function create() {
    text = game.add.bitmapText(0, 0, 'desyrel', 'bar', 64);
    text.tint = 0x55ff55;
}

Once the page loads, type this in the console:

text.text = 'foobar';

Result:

image

As a workaround, you can type this in the console after setting the text:

text.removeChildren();
text.purgeGlyphs();

Correct result:

image

I'm using Phaser 2.4.2 and Chromium 43.0.2357.130 Ubuntu 14.04 (64-bit).

@Cristy94
Copy link

Cristy94 commented Aug 2, 2015

I think .text property is read only, and you should use text.setText('foobar') instead. http://phaser.io/docs/2.3.0/Phaser.BitmapText.html#setText

@Pajamaman
Copy link
Author

Same result with setText().

@Cristy94
Copy link

Cristy94 commented Aug 2, 2015

What about calling .updateText() after you set it?

@Pajamaman
Copy link
Author

.updateText() is called by the text property setter. In other words, nope.

I think the fix for this is to change line 372 of BitmapText.js from this:

var g = this._glyphs[t];

To this:

var g = Phaser.Group.prototype.filter.call(this, function (glyph) { return glyph.name == line.text[c] }).list[0];

I don't see anywhere else in the source where a method from another class is called like this however. If this goes against convention or is just too ugly, we could put the filter method into Utils or something. It could even be made static.

Another fix is to change line 374 from this:

if (g)

To this:

if (g && g.name == line.text[c])

I don't like this because I don't think we should assume that this._glyphs[t] will be the glyph we're looking for.

Of course we could always use Array.prototype.filter but I don't see that anywhere else in the source either. I assume this is because Phaser is meant to support older browsers.

@photonstorm
Copy link
Collaborator

Actually I think it's directly related to this: 9362a2b

@photonstorm
Copy link
Collaborator

This is now fixed in a dev - and didn't require anything as intense as any of the suggestions above thankfully :)

@Pajamaman
Copy link
Author

Oh, hah. That's much simpler indeed. Thanks for the speedy fix!

@DDowell
Copy link

DDowell commented Feb 17, 2017

I still get it in 2.6.1 albeit not as frequent. I first had the setText outside of the phaser game loop but even after moving it into the game loop, it happens from time to time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants