Sign in to follow this  

Making text stick to a button / using the 'parent' property

Recommended Posts


I wanted to create draggable buttons with some bitmaptext on them.


I ended up with this:

// the buttonvar button =, y, "button", 0);button.input.enableDrag(false, false);// an intermediary group, just to be able to set the draggable 'button' as parentvar group = new Phaser.Group(, button);// the text that i want to stick to the buttonvar text = new Phaser.BitmapText(, 2, 2, "main-font", "text!!");group.add(text);

Is there a more clever way to do this? For instance, the text has a 'parent' property that I can set directly, skipping the group.

text.parent = button; 

I suppose that's from PIXI.GameObjectContainer. Presently, setting it as above works. Is there a safe way to use it, or some other way to use sprites/images/"gameobjectcontainers" as parents directly?


Share this post

Link to post
Share on other sites

I'm almost positive that you can do this:

button.addChild(text);   //Appends the text as a child of the buttonbutton.getChildAt(0);    //Obtains the child in position 0 of the button

This seems to be what you're trying to accomplish and you don't need the group

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.