在某种程度上这是有效的,但是只有当它的y位置从<开始时才移除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);
if(tempBullet.y < 200)
{
bullets.splice(tempBullet, 1);
stage.removeChild(tempBullet);
}
bulletTimeOut = 5;
}
答案 0 :(得分:0)
此代码是否在循环中发生?
我认为不仅仅是检查tempBullet
的位置,而是想要遍历整个项目符号数组,以删除任何超过200px的项目符号。
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);
}
}