wombat Posted April 24, 2014 Share Posted April 24, 2014 Hi,I wanted to create draggable buttons with some bitmaptext on them. I ended up with this:// the buttonvar button = this.game.add.button(x, 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(this.game, button);// the text that i want to stick to the buttonvar text = new Phaser.BitmapText(this.game, 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? Link to comment Share on other sites More sharing options...
Massemassimo Posted April 29, 2014 Share Posted April 29, 2014 Very good question in my eyes, looking for something like this, too. Thanks for the group idea though, that'll work in the meantime! Link to comment Share on other sites More sharing options...
ctmartinez1992 Posted April 29, 2014 Share Posted April 29, 2014 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 buttonThis seems to be what you're trying to accomplish and you don't need the group Kapsonfire 1 Link to comment Share on other sites More sharing options...
farzher Posted April 29, 2014 Share Posted April 29, 2014 I needed to add some text to a sprite. addChild worked there too. How was I supposed to know this method even existed? I didn't see it in the documentation http://docs.phaser.io/Phaser.Sprite.html#Sprite Link to comment Share on other sites More sharing options...
Kapsonfire Posted May 8, 2014 Share Posted May 8, 2014 Phaser.Sprite is inherited by Pixi.Sprite and Pixi.Sprite is having the addChild function.http://www.goodboydigital.com/pixijs/docs/classes/Sprite.html farzher 1 Link to comment Share on other sites More sharing options...
Recommended Posts