Sign in to follow this  

How can add a label over sprite?

Recommended Posts

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 =, 20, "0", style); <---- this one works on game screen
this.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.

Share this post

Link to post
Share on other sites
var style = { font: "30px Arial", fill: "#ffffff" };  this.label_score =, 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.

Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.