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

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.