下面是添加到舞台的对象的代码,然后检查新添加的对象是否与以前的对象重叠。问题是当玩家移动时,由于不断生成随机对象,舞台上的对象会随机移动。这在进入帧计时器中调用
if(onStageCount < 15){
var Square:MovieClip;
Square = new mcSquare();
Square.x = Math.random() * 1000 + ((Math.abs(_boundaries.x) + (stage.stageWidth)));
Square.y = Math.random() * stage.stageHeight/2.5 + (stage.stageHeight/2.5);
ObjectArray.push(Square);
onStageCount += 1;
}
for (var i in ObjectArray){
for (var a in ObjectArray){
if(ObjectArray[i].hitTestObject(ObjectArray[a]) && a != i){ChildrenColliding = true;}
while(ChildrenColliding){
ObjectArray[i].x += (ObjectArray[a].width + 75);
ObjectArray[i].y += (ObjectArray[a].height + 40);
ChildrenColliding = false;
if(ObjectArray[a].hitTestObject(ObjectArray[i]) && a != i){ChildrenColliding = true;}
}
}
_boundaries.addChild(ObjectArray[i]);
}