Work with group

Hello guys!
I’ve been researching and I’ve seen some tools for groups, but I don’t understand very well. I want to create a group called enemyGroup() and inside it I want to add several sprites (ex: add 500 enemies A and then 500 enemies B, as I don’t use destroy() to save memory, so I wanted to add the 500+500 in one single group and use a “key” to distinguish between using a get call only enemyGroup.get(A) or enemyGroup.get(B)). Would it be possible? Or would I have to create subroutines? Otherwise, it would be better to create several groups, because routines would consume too much processing.
Thanks.

You can use

const enemiesA = enemyGroup.getMatching('name', 'A');

or something similar.

But you can also make three groups (enemies, enemiesA, enemiesB) and use get() only on the A and B groups.

1 Like

Hello,


so it would be groupEnemyes.add(groupEnemyA)
groupEnemyes.add(groupEnemyB)
groupEnemyes.add(groupEnemyC)
let A = groupEnemyes.getMatching(groupEnemyA)

?
thanks!

I think it will be better to use 3 groups, not getMatching().

enemiesA.createMultiple(/*…*/);
enemiesB.createMultiple(/*…*/);

enemies.add(enemiesA.getChildren());
enemies.add(enemiesB.getChildren());

const someEnemyA = enemiesA.getFirstAlive(false);
1 Like