Jump to content

Trying to loop through just children of group


ForgeableSum
 Share

Recommended Posts

EDIT: I should reword the title. It should say: trying to loop through children's children of group. 

 

So I'm trying to determine if sprites in a group are in range of each other. When the sprites get in range, they automatically attack each other. I figured the best way to do this would be to create an invisible sprite, add it as a child of each sprite, then check for overlap in the update function. I could then do a callback function on all overlapping bodies, having the parent of one overlapping body attack the other. Seems simple, in concept. But I haven't figured out a way to perform overlaps on just the invisible children of the sprites in the group. In other words, I'm trying to do something like this:

 

if (game.physics.arcade.overlap(spriteGroup)) {
console.log('overlaps'); 
}
 
But instead of checking overlap on the children of group "spriteGroup," I want to check overlap on the children's children of spriteGroup. Because the bodies I want to check for overlap are children of the sprites in spriteGroup. 
 
Any suggestions?
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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