I'm trying to get containers within containers that I've stored in a Containers array. Sounds confusing, so here's the code:
First I make individual containers to store BMP and label for People and Animals: (I will make a new container for each instance of a NPC because I want individual control over BMP and associated Label).
peopleContainer.addChild(peopleBMP, peopleLabel);
animalContainer.addChild(animalBMP, animalLabel);
animalContainer2.addChild(animalBMP, animalLabel);
I then assign them names and IDs:
peopleContainer.name = "peopleContainer1";
peopleContainer.id = 0;
animalContainer.name = "animalContainer1";
animalContainer.id = 1;
animalContainer2.name = "animalContainer2";
animalContainer2.id = 2;
I then want to create Containers that store these individual containers:
ContainerOfPeople = new createjs.Container();
ContainerOfPeople.name = "Container Of People";
ContainerOfPeople.id = 0;
ContainerOfPeople.addChild(peopleContainer);
ContainerOfAnimals = new createjs.Container();
ContainerOfAnimals.name = "Container Of Animals";
ContainerOfAnimals.id = 1;
ContainerOfAnimals.addChild(animalContainer, animalContainer2);
I then add those big containers to an array
NPC_Array.push(ContainerOfPeople, ContainerOfAnimals);
Now, I'd like to loop through the array of big containers, and get the individual IDs of the containers within the big containers... That way I can check their individual distances to see which is closest to the player...
function checkDistance2() {
//loop through Containers Array [ContainerOfAnimals, ContainerOfPeople]...
for (var index = 0; index < NPC_Array.length; index++) {
console.log(NPC_Array[index].children[0].name);
}
}
This gives the output:
peopleContainer1
animalContainer2
It seems to be working, but it's skipping over the first animalContainer (name animalContainer1
) within ContainerOfAnimals. Why is that?
Thanks!