Jump to content

Add sprite to several groups


charlie_says
 Share

Recommended Posts

I'm sure this must have been asked before, but I couldn't find anything...

 

I currently have a custom depth sort, which I do through a group. But I also need to do a collision detection, which would require a different group. (And, no, there's not really a way to combine these groups).

 

You don't seem to be able to add a sprite to multiple groups, but I can't see a work around for the ability to do both...

 

Any ideas?

Link to comment
Share on other sites

No but you can add a sprite to multiple arrays, and the collision/overlap functions will take an array instead of a group for the second parameter. Try to think of groups as visual containers (which they are, essentially being slightly modified DisplayObjectContainers from pixi) rather than simple abstract lists. You can easily replicate most of the convenience functions found in Group using basic arrays just by making use of array methods like filter, map, forEach and so on.

Link to comment
Share on other sites

Here's the bit in the docs, just to ensure I'm not making this up! http://docs.phaser.io/Phaser.Physics.Arcade.html#overlap

 

If it definitely isn't working (and I can't see why not, looking at the source it seems to be in order) then it may be an unnoticed bug. Certainly I don't think many people tend to use arrays, most probably finding groups work fine for their needs.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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