Jump to content

Can text be added to a group? Or only sprites?


oakler
 Share

Recommended Posts

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 work

If 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

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

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

  • 2 weeks later...
 Share

  • Recently Browsing   0 members

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