Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays AS3:阵列中的独立实例?_Arrays_Actionscript 3_Flash_Actionscript_Instances - Fatal编程技术网

Arrays AS3:阵列中的独立实例?

Arrays AS3:阵列中的独立实例?,arrays,actionscript-3,flash,actionscript,instances,Arrays,Actionscript 3,Flash,Actionscript,Instances,我在as3中制作了一个侧滚游戏,玩家可以生成自动走向屏幕另一侧出口的单位,但是有塔阻止它们。我想让塔楼分开拍摄,有什么办法吗? 这是我的代码,一旦if语句得到满足,所有的塔都会同时开火 private function tower1Fire():void { for (var j:int = creep1Array.length - 1; j >= 0; j--) { for each (va

我在as3中制作了一个侧滚游戏,玩家可以生成自动走向屏幕另一侧出口的单位,但是有塔阻止它们。我想让塔楼分开拍摄,有什么办法吗? 这是我的代码,一旦if语句得到满足,所有的塔都会同时开火

    private function tower1Fire():void 
    {
            for (var j:int = creep1Array.length - 1; j >= 0; j--)
            {
                for each (var towerOne:mcTower1 in tower1Array)
                {
                    if (creep1Array[j].x - towerOne.x <= 100 && creep1Array[j].y > towerOne.y)
                    {
                        var newTower1Bullet:mcLaser1 = new mcLaser1;
                        newTower1Bullet.x = towerOne.x;
                        newTower1Bullet.y = towerOne.y;
                        tower1BulletArray.push(newTower1Bullet);
                        stage.addChild(newTower1Bullet);
                    }
                }
            }
    }

我没有得到任何错误。任何回复将不胜感激,谢谢

据我所知,你所有的塔都将在一个“帧渲染”中“开火”,这就是为什么它们看起来像是同时开火的原因。(因为整个循环将在单个绘图操作中执行)

如果我是你,我会听输入帧事件,并记录帧数。。。。我只会发射一座塔,每10-20帧发射一次。所以

private ENTER_FRAME(event:Event):void
{

    if(frameCount >= 20)
    {
        // TODO: fire logic goes here

        // reset the frameCount to zero
        frameCount = 0;

        // you need to keep a running index of your towers, 
        // so the next time your code executes, it will fire the next tower
        towerIndex++
    }
    frameCount++;
}

所以,如果你这样做,你就不会有for循环。

嗨,谢谢你的回复。现在的问题是,我希望塔只有在附近有爬行动物时才会开火,而现在,如果爬行动物在塔附近,所有塔都会开火。我不能在您刚刚编写的代码中添加“if”语句,对吗?很抱歉,我对as3还是相当陌生……是的,你可以,所以我在添加“fire logic goes here”的地方,你可以检查附近是否有爬行动物。对不起,第一次我不太明白。。。因此,您可能只希望在if语句中增加towerindex。
private ENTER_FRAME(event:Event):void
{

    if(frameCount >= 20)
    {
        // TODO: fire logic goes here

        // reset the frameCount to zero
        frameCount = 0;

        // you need to keep a running index of your towers, 
        // so the next time your code executes, it will fire the next tower
        towerIndex++
    }
    frameCount++;
}