如何从数组中调用多个对象,每个对象都有自己的属性?

时间:2016-08-04 09:35:31

标签: actionscript-3

我在舞台上有一些球(比如10个球)和相同的实例名称"球"和4层楼的地板向上铺设地板和左侧地板。 球在地板上反弹,一切都很好。 现在,如果球击中了敌人,我想要从新的Array.i尝试产生另一个具有相同属性的球。但是当第一个球产生它弹跳但是当另一个球击中敌人时,第二个球产生了与第一个球相同的属性而不是它自己的属性。

import flash.events.Event;

stop();


var downFloorArray:Array = new Array();
for (var df:int = numChildren - 1; df>= 0; df--)
{
    var childdf:DisplayObject = getChildAt(df);
    if (childdf.name == "downFloor")
    {
        downFloorArray.push(MovieClip(childdf));
    }
}

var rightFloorArray:Array = new Array();
for (var rf:int = numChildren - 1; rf>= 0; rf--)
{
    var childrf:DisplayObject = getChildAt(rf);
    if (childrf.name == "rightFloor")
    {
        rightFloorArray.push(MovieClip(childrf));
    }
}

var leftFloorArray:Array = new Array();
for (var lf:int = numChildren - 1; lf>= 0; lf--)
{
    var childlf:DisplayObject = getChildAt(lf);
    if (childlf.name == "leftFloor")
    {
        leftFloorArray.push(MovieClip(childlf));
    }
}

var upFloorArray:Array = new Array();
for (var uf:int = numChildren - 1; uf>= 0; uf--)
{
    var childuf:DisplayObject = getChildAt(uf);
    if (childuf.name == "upFloor")
    {
        upFloorArray.push(MovieClip(childuf));
    }
}

var ballArray:Array = new Array();
for (var b:int = numChildren - 1; b>= 0; b--)
{
    var childb:DisplayObject = getChildAt(b);
    if (childb.name == "ball")
    {
        ballArray.push(MovieClip(childb));
        MovieClip(childb).ballY = 20;
        MovieClip(childb).ballX = 3;
    }
}







stage.addEventListener(Event.ENTER_FRAME,gameLoop);
function gameLoop(event:Event):void
{
    for (var sab:int=ballArray.length-1; sab>=0; sab--)
    {
        ballArray[sab].ballY--;
        ballArray[sab].x +=  ballArray[sab].ballX;
        ballArray[sab].y -=  ballArray[sab].ballY;
        for (var sadf:int=downFloorArray.length-1; sadf>=0; sadf--)
        {
            if (downFloorArray[sadf].hitTestPoint(ballArray[sab].x,ballArray[sab].y + 27))
            {
                ballArray[sab].ballY = 20;
            }
        }
        for (var sarf:int=rightFloorArray.length-1; sarf>=0; sarf--)
        {
            if (rightFloorArray[sarf].hitTestPoint(ballArray[sab].x + 20,ballArray[sab].y))
            {
                ballArray[sab].ballX = -3;
            }
        }
        for (var salf:int=leftFloorArray.length-1; salf>=0; salf--)
        {
            if (leftFloorArray[salf].hitTestPoint(ballArray[sab].x - 20,ballArray[sab].y))
            {
                ballArray[sab].ballX = 3;
            }
        }
        for (var sauf:int=upFloorArray.length-1; sauf>=0; sauf--)
        {
            if                       `(upFloorArray[sauf].hitTestPoint(ballArray[sab].x,ballArray[sab].y - 27))`
            {
                ballArray[sab].ballY = -3;
            }
        }
        if (ballArray[sab].hitTestObject(enemy))
        {

        }
    }
}

0 个答案:

没有答案