Jump to content

Getting elements from Group


Draconar
 Share

Recommended Posts

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 variable
  • get 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

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 like

group.remove(member);
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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