Jump to content

How to position elements inside a group?


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?



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); 


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

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.


  • Recently Browsing   0 members

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