Draconar Posted June 22, 2015 Share Posted June 22, 2015 How do I pick specific members of a group? My naive solution was: create all elements and add them to the group (basic for loop)at the same step, add the created element to an Array variableget specific members at play time by their Array's reference Besides that, how do I change a member's group? For example, there is a hockey team group and there is a Player+ball group, any member of Hockey's team can become a Player+ball group. Link to comment Share on other sites More sharing options...
MikauSchekzen Posted June 23, 2015 Share Posted June 23, 2015 If you want to target specific members of a group, I believe you'll have to iterate through all of them. For example:group.forEach(function(member, param1) { if(param1 > 50 && member.hp < 250) { // do stuff }}, this, true, param1);I think Phaser objects that can be in a group aren't restricted to just that group. But if you later want to get the same targets again later, it's probably better for performance to add them in a new group, rather than iterate through the main group over and over again. And if you want to remove a member from a group, do something likegroup.remove(member); Draconar 1 Link to comment Share on other sites More sharing options...
drhayes Posted June 23, 2015 Share Posted June 23, 2015 FWIW, Phaser objects can only be in one group at a time. Adding a Phaser object to a new group will remove it from the old group. Link to comment Share on other sites More sharing options...
Draconar Posted June 23, 2015 Author Share Posted June 23, 2015 FWIW, Phaser objects can only be in one group at a time. Adding a Phaser object to a new group will remove it from the old group. This is great. Exactly what I need. I want to remove a member from a group and insert it into another. How can I do that? Link to comment Share on other sites More sharing options...
Recommended Posts