I'd like to change the coordinates of 2 children containers within a parent container. Originally, I was looping through the children of the parent container and changing their x,y
individually... but then it made more sense to just change the parent container's x,y
...
The issue with that is... I need to get the individual altered coordinates of each child... But changing the parent container's coordinates doesn't seem to change the children's coordinates in relation to the stage...
The question is... how can I get the changing x,y
of the children when I alter their parent's x,y
?
Thanks
So if I'm moving the container of children around as such:
function NPCMove() {
if (pointA) {
if (ContainerOfAnimals.x < 400) {
ContainerOfAnimals.x +=2;
}
else {
pointA = false;
pointB = true;
}
}
else if (pointB) {
if (ContainerOfAnimals.x > 100) {
ContainerOfAnimals.x-=2;
}
else {
pointB = false;
pointA = true;
}
}
}
I can check the distance of the player to each child in the Parent Container as such using localToGlobal
? (NPC_Array contains Parent Containers)
for (var i = 0; i < NPC_Array.length; i++) {
//get children containers of each big Container
for (var j = 0; j < NPC_Array[i].children.length; j++) {
//need child.x's global location now...
var pt = NPC_Array[i].localToGlobal(NPC_Array[i].children[j].x, NPC_Array[i].children[j].y);
var distX = Math.abs(players_Array[0].x - pt.x);
var distY = Math.abs(players_Array[0].y - pt.y);
if (distX < 50 && distY < 50) {
//Player is near child...