Jump to content

Does Phaser have anything like Tags?


boolean
 Share

Recommended Posts

Hi there

 

I'm just getting started with Phaser, so hopefully this isn't an old/silly question.

 

I've been using groups in my game and they are pretty handy. I figure they are like adding folders to the hierarchy view in Unity (where you can group a bunch of elements together). I notice that it has a forEach method you can call that quickly cycles through all the entities inside the group.

 

However, groups are a container for any mixture of entities - for example I might have a group called "titleGroup" made up of several different UI elements. This makes applying actions to groups difficult since I can't be sure what methods are available.

 

In Unity we also have Tags. These let you tag entities by their type, which is separate from groups which are just a container of entities in the game world. The main advantage of tags is I could do a forEach on a tag type and know that every entity I'm cycling through is the same type. For example, my container of UI elements might have some buttons, a window, a image, all in a group call "titleGroup". With tags I could say 'foreach entity with tag 'button', set as disabled". Likewise, I might have 3 groups of enemy types, but if I do a linecast I don't want to cycle through all three groups manually, I would prefer to just do 'forEach tag of Enemy'.

 

Does Phaser have anything like this? 

Link to comment
Share on other sites

That's good to know, I'll use that for now.

 

Just out of curiosity, I assume though that if I have three groups I would still have to iterate through each group individually? By that I mean, there isn't a way I can globally say "Get me every entity in the game world with the tag X and forEach through it"?

 

If that isn't possible, perhaps I can add my entities to two groups - one for their container in the game world another group for their tag/type (I could just dump that into the constructor then). I think that should work. 

 

Thanks!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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