【发布时间】:2013-08-16 17:18:42
【问题描述】:
我想更改父容器中 2 个子容器的坐标。最初,我循环遍历父容器的子容器并单独更改它们的x,y...但随后更改父容器的x,y 更有意义...
问题是...我需要获取每个子容器的单独更改坐标...但是更改父容器的坐标似乎不会更改子容器相对于舞台的坐标...
问题是......当我改变他们父母的x,y时,我怎样才能得到孩子们不断变化的x,y?
谢谢
所以如果我这样移动儿童容器:
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;
}
}
}
我可以使用localToGlobal 来检查玩家与父容器中每个孩子的距离吗? (NPC_Array 包含父容器)
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...
【问题讨论】:
标签: javascript createjs