我试图在玩家面前无限生成 x 距离的平台,但我几乎不知道从哪里开始。他们也不能“堆叠”在彼此之上。目前,我所拥有的如下,没有错误,虽然它占用了相当多的内存,而且我的游戏滞后到了 flash cs3 崩溃的地步
function enterFrameHandler(e:Event):void{
//gravitate the player
_vy += 1.5;
//move the player
Player.x += _vx;
Player.y += _vy;
//process collisions
processCollisions();
//Process other collisions
processOtherCollisions();
//scroll the stage
scrollStage();
//Process Key Presses
KeyHandler();
//Process Lives once
LifeHandler();
//Generate Objects
generateObjects();
}
//Function for generating objects
var ObjectArray:Array = [];
var ChildrenColliding:Boolean = false;
function generateObjects():void{
if(_vx > 0){
var Square:MovieClip;
Square = new mcSquare();
Square.x = Math.random() * 500 + Math.abs(_boundaries.x);
Square.y = Math.random() * stage.stageHeight/2.5 + (stage.stageHeight/2.5);
ObjectArray.push(Square);
_boundaries.addChild(Square);
}
for(var i in ObjectArray){
for(var a in ObjectArray){
if(ObjectArray[a].hitTestObject(ObjectArray[i]) && a != i){
ChildrenColliding = true;
}
}
while(ChildrenColliding){
ObjectArray[i].x = Math.random() * 500 + Math.abs(_boundaries.x);
ObjectArray[i].y = Math.random() * stage.stageHeight/2.5 + (stage.stageHeight/2.5);
}
}
}