1

在某种程度上这是可行的,但它只会在 tempBullet 对象的 y 位置从 < 200 开始时删除它,而不是在它在舞台下方的某个地方生成后到达该点:

        if(firing && bulletTimeOut == 0)
        {
            var tempBullet = new Bullet();
            bullets.push(tempBullet);
            tempBullet.x = x;
            tempBullet.y = y-10;
            stage.addChild(tempBullet);
            trace(bullets.length);
            if(tempBullet.y < 200)
            {
                bullets.splice(tempBullet, 1);
                stage.removeChild(tempBullet);
            }
            bulletTimeOut = 5;
        }
4

1 回答 1

0

这段代码是循环发生的吗?

我认为这不仅仅是检查您的位置,tempBullet而是打算遍历整个子弹阵列以删除任何超过 200 像素的子弹。

if(firing && bulletTimeOut == 0)
{
    var tempBullet = new Bullet();
    bullets.push(tempBullet);
    tempBullet.x = x;
    tempBullet.y = y-10;
    stage.addChild(tempBullet);
    trace(bullets.length);
    bulletTimeOut = 5;
}
// test bullet positions whether firing or not
for each (b:Bullet in bullets) {
    if(b.y < 200)
    {
        bullets.splice(b, 1);
        stage.removeChild(b);
    }
}
于 2013-01-20T20:31:36.687 回答