goyeneche Posted October 30, 2015 Share Posted October 30, 2015 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"Preloadgame.load.bitmapFont('font', 'assets/fonts/font.png', 'assets/fonts/font.fnt');CreatelabelHP = 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.thanks Link to comment Share on other sites More sharing options...
chongdashu Posted October 30, 2015 Share Posted October 30, 2015 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?) Link to comment Share on other sites More sharing options...
goyeneche Posted October 30, 2015 Author Share Posted October 30, 2015 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";..Also..labelHP.setText("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 More sharing options...
chongdashu Posted October 30, 2015 Share Posted October 30, 2015 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? Link to comment Share on other sites More sharing options...
goyeneche Posted October 30, 2015 Author Share Posted October 30, 2015 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 More sharing options...
goyeneche Posted October 30, 2015 Author Share Posted October 30, 2015 Oh I get it, by default littera doesn't include numbers! so I exported the bitmap without numbers... chongdashu 1 Link to comment Share on other sites More sharing options...
Recommended Posts