Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Bitmap Fonts - Error on change text


Recommended Posts

I am trying to use bitmap fonts, it actually works, but when I try to change the value I get:

"Uncaught TypeError: Cannot read property 'texture' of undefined"


game.load.bitmapFont('font', 'assets/fonts/font.png', 'assets/fonts/font.fnt');


labelHP = game.add.bitmapText(10, 10, 'font','HP',22);labelHP.text = 'HP' + player.model.state.life // This causes the error.labelHP.fixedToCamera = true;

I used littera to generate the font.


Link to comment
Share on other sites

Could you post the stack trace?  -- the error doesn't really give too much information.

For a quick test, could you try just doing something like: 


labelHp.text = "HP1337";


And see if it works?


If it does, it's likely something is weird over with your player.model.state.life variable (e.g., are you sure it is a string?)

I tried with only text:

labelHP.text = "HP1337";



but gives me the same error:

phaser.min.js:17 Uncaught TypeError: Cannot read property 'texture' of undefined(…)


Link to comment
Share on other sites

So if you leave it as:

labelHP = game.add.bitmapText(10, 10, 'font','HP',22);labelHP.fixedToCamera = true;

Does it work and render the string "HP" without any problems?

Yes, no errors and it shows in the game.

I did it from scratch following phaser's examples and I find the problem. It only works if the text contains only string chars.

For example this works:


labelHP = game.add.bitmapText(10, 10, 'font','HP',22);labelHP.text = "test";labelHP.fixedToCamera = true;

this not:

labelHP = game.add.bitmapText(10, 10, 'font','HP',22);labelHP.text = "test1"; // <------labelHP.fixedToCamera = true;
Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...