Jump to content

How to position elements inside a group?


trueicecold
 Share

Recommended Posts

I'm trying to make a simple button with text on it. I could see the group resizes to the size of it's sprite image children, which is great. Now, I want text centered inside the group.

However, when I position the sprite image/text, they get the world coordinates, rather than the group starting point...

this.new_game = this.add.group();this.button = this.add.sprite(0, 0, "button_bg");this.text = this.add.text(0, 0, "New Game", {font:"20px",fill:"#ffffff",align:"center"});this.new_game.add(this.button);this.new_game.add(this.text);

How do I fix this?

 

Thanks!

Link to comment
Share on other sites

this.new_game = this.add.group();this.button = this.add.sprite(0, 0, "button_bg", null, this.new_game);this.text = this.add.text(0, 0, "New Game", {font:"20px",fill:"#ffffff",align:"center"}, this.new_game); 

or

this.new_game = this.add.group();this.button = this.make.sprite(0, 0, "button_bg");this.text = this.make.text(0, 0, "New Game", {font:"20px",fill:"#ffffff",align:"center"});this.new_game.add(this.button);this.new_game.add(this.text);

 

I think both of those ways should work, but I didn't test.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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