charlie_says Posted July 19, 2014 Share Posted July 19, 2014 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 More sharing options...
lewster32 Posted July 19, 2014 Share Posted July 19, 2014 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 More sharing options...
charlie_says Posted July 19, 2014 Author Share Posted July 19, 2014 pushing an array to game.physics.arcade.overlap doesn't seem to work (whereas when they're groups it's fine.) Link to comment Share on other sites More sharing options...
lewster32 Posted July 19, 2014 Share Posted July 19, 2014 Are you passing the array as the second parameter? Only the second parameter can be an array, the first must be a Sprite, Group or Emitter. Link to comment Share on other sites More sharing options...
lewster32 Posted July 19, 2014 Share Posted July 19, 2014 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 More sharing options...
charlie_says Posted July 20, 2014 Author Share Posted July 20, 2014 Thanks for that lewster32.You are indeed correct, it works fine, I was trying array against array, which isn't supported (unfortunately). Link to comment Share on other sites More sharing options...
lewster32 Posted July 20, 2014 Share Posted July 20, 2014 I don't see any reason why group vs group should be supported but array vs array shouldn't, so maybe you should suggest this in an issue on Github? All it does internally with group vs group is iterate through the children (which is an array) anyway. Link to comment Share on other sites More sharing options...
Recommended Posts