Jump to content

Can someone help explain Groups.RETURN_ALL?


Langusmon
 Share

Recommended Posts

The functionality behind the groups RETURN_ALL doesnt seem to be working the way that I was expecting it to.

Lets say I have two groups, each represents an army, but I want to pull out certain soldiers from the groups to do combat based on their location.

group1 = player1_army.iterate('location','PLACE1',Phaser.Group.RETURN_ALL);
group2 = player2_army.iterate('location','PLACE2',Phaser.Group.RETURN_ALL);

I was expecting group1 and group2 to be actual groups, but they dont seem to be.
This doesnt work:

group1.getAt(0) 


But this does work:

group1[0]

Also, if destroy an element from group1, it does actually destroy the sprite from player1_army , but the length of group1 doesnt decrease, it just stays in group1 as if nothing has changed.

Based on what I can find in the documentation, is group1 just an array of sprites and not an actual group? If i wanted for an element to be removed from group1 after I destroy , do I need to do something like group1[-0] or something?

Looking to understand how this is working, thanks!

 

Link to comment
Share on other sites

results1 = player1_army.iterate('location', 'PLACE1', Phaser.Group.RETURN_ALL);
results2 = player2_army.iterate('location', 'PLACE2', Phaser.Group.RETURN_ALL);

RETURN_ALL returns all the matching items in a plain array. It doesn't create a new Group or move the sprites from their current Group. You would have to splice the array if you wanted to update its length.

If you want to create new groups, you would do 

var group1 = this.add.group();
var group2 = this.add.group();

player1_army.moveAll(player1_army.iterate(/* … */), group1);
player1_army.moveAll(player1_army.iterate(/* … */), group2);

 

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...