oakler Posted December 16, 2013 Share Posted December 16, 2013 Hi, Is it possible to add text to a group? Or is it limited to only sprites? I tried code like this to no avail:foo = game.add.group();foo.create(0,0,'bar'); // adding a spritefoo.add.text(0, 10, 'some text', { 'font': '22px Helvetica', fill: '#fff' }); // doesn't workIf text can't be added to a group is there some workaround for creating text that can be manipulated along with sprites as part of the same unit? Thank you Link to comment Share on other sites More sharing options...
XekeDeath Posted December 16, 2013 Share Posted December 16, 2013 Create the text separately, and add it afterwards.var group = game.add.group();group.create(0,0,"sprite"); //will only ever create and add sprites.var text = new Phaser.Text(game, 0, 0, "Text", {/*style object*/});group.add(text);//Ortext = game.add.text(0, 0, "Text", {/*style object*/});group.add(text);This works for tile sprites as well, as you can't create them directly on the group. Edit: fixed the reference to the GameObjectFactory in the second option... Link to comment Share on other sites More sharing options...
rich Posted December 16, 2013 Share Posted December 16, 2013 In 1.1.4 I added the ability to do this:text = game.add.text(0, 0, "Text", {/*style*/}, otherGroup);Where 'otherGroup' is a new parameter allowing you to specify which Group it gets added to. This parameter has been added to most of the methods in GameObjectFactory. kray and bazoo 2 Link to comment Share on other sites More sharing options...
XekeDeath Posted December 16, 2013 Share Posted December 16, 2013 In 1.1.4 I added the ability to do this:text = game.add.text(0, 0, "Text", {/*style*/}, otherGroup);Where 'otherGroup' is a new parameter allowing you to specify which Group it gets added to. This parameter has been added to most of the methods in GameObjectFactory.That's handy, it'll cut my creation code down by about a quarter! Link to comment Share on other sites More sharing options...
oakler Posted December 24, 2013 Author Share Posted December 24, 2013 Thank you XekeDeath and Rich! This is a huge help. Best Link to comment Share on other sites More sharing options...
Recommended Posts