我正在使用 as3 创建一个平台游戏,需要查看movieclip _boundaries 的孩子是否在舞台上,这样我可以删除它们并降低计数器,以便不断生成更多。到目前为止,我所拥有的一切都在下面。请帮助,被困在这个几个星期。
var ObjectArray:Array = [];
var ChildrenColliding:Boolean = false;
var onStageCount:Number = 0;
function generateObjects():void{
if(_vx > 0 && onStageCount < 20){
var Square:MovieClip;
Square = new mcSquare();
Square.x = Math.random() * 1000 + (Math.abs(_boundaries.x) + 50);
Square.y = Math.random() * stage.stageHeight/2.5 + (stage.stageHeight/2.5);
ObjectArray.push(Square);
_boundaries.addChild(Square);
onStageCount += 1;
}
for(var i in ObjectArray){
Square[i] = Square.name;
for(var a in ObjectArray){
if(ObjectArray[i].hitTestObject(ObjectArray[a]) && a != i){ChildrenColliding = true;}
while(ChildrenColliding){
ObjectArray[i].x += (ObjectArray[a].height + 25);
ObjectArray[i].y += (ObjectArray[a].width + 25);
ChildrenColliding = false;
if(ObjectArray[a].hitTestObject(ObjectArray[i]) && a != i){ChildrenColliding = true;}
}
}
}
//CHECK TO SEE IF CHILDREN ARE ON STAGE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
for(var w in ObjectArray){
if(_boundaries){
onStageCount -= 1;
trace("removed");
_boundaries.removeChild(ObjectArray[w]);
ObjectArray.splice(w, 1);
}
}
}