Langusmon Posted March 4, 2018 Share Posted March 4, 2018 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 More sharing options...
samme Posted March 4, 2018 Share Posted March 4, 2018 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); Langusmon 1 Link to comment Share on other sites More sharing options...
Langusmon Posted March 6, 2018 Author Share Posted March 6, 2018 @samme Thanks! makes perfect sense. samme 1 Link to comment Share on other sites More sharing options...
Recommended Posts