fran Posted June 22, 2014 Share Posted June 22, 2014 Hello, I would like to know how to attach a label over character head, something like in the next image: I tried: var style = { font: "30px Arial", fill: "#ffffff" }; //this.label_score = this.game.add.text(20, 20, "0", style); <---- this one works on game screenthis.label_score = this.hello_sprite.add.text(20, 20, "0", style);But it didn't worked. The label must follow the character on screen.Thanks in advance. Link to comment Share on other sites More sharing options...
lewster32 Posted June 22, 2014 Share Posted June 22, 2014 var style = { font: "30px Arial", fill: "#ffffff" }; this.label_score = this.game.add.text(20, 20, "0", style);this.hello_sprite.addChild(this.label_score);When adding something to a sprite, you use addChild, which is not defined in Phaser, but in pixi - so easy to miss if you're only consulting Phaser docs. fran 1 Link to comment Share on other sites More sharing options...
fran Posted June 22, 2014 Author Share Posted June 22, 2014 Thank you very much, did what I needed. I will have a look to pixi docs too. Regards. tanmoy749 and lewster32 1 1 Link to comment Share on other sites More sharing options...
Jimaginary Posted April 26, 2017 Share Posted April 26, 2017 Hi, just to clarify - is there really no way to add text to a sprite? It always had to be added to the game over? I'm creating a game where the labels are over the characters' heads, but the characters are moving so every time I move the character I have to also move it's corresponding text field. It just seems more verbose and computationally expensive than adding text as a child of a sprite. tanmoy749 1 Link to comment Share on other sites More sharing options...
Recommended Posts