【发布时间】:2012-05-22 18:10:18
【问题描述】:
我试图在玩家面前无限生成 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);
}
}
}
【问题讨论】:
-
附带说明,从惯用的角度来看,您的 AS3 代码令人困惑。 AS3 中的变量往往是驼峰式(或有时是下划线命名),而类往往是 PascalCased。混合使用这些大小写会使阅读变得困难。
标签: arrays actionscript-3