【发布时间】:2013-08-19 22:12:05
【问题描述】:
所以我试图制作一个子弹船 hitTestObject ,但我不知道为什么代表 bullets.length 的变量不会改变。
所以错误来自这个函数
function doShips() {
trace("bcount :" + bcount)
trace("_bulletsArray length:" + _bulletsArray.length)
for (var i:int = shipArray.length - 1; i >= 0; i--) {
shipArray[i].moveDown() //what the code in the Ship and Ship2 class does -> only: this.y += 3
for (var bcount= _bulletsArray.length-1; bcount >= 0; bcount--) {
//if the bullet is touching the ship
while (shipArray[i].hitTestObject(_bulletsArray[bcount])) {
//if we get here it means there`s is a collision
removeChild(_bulletsArray[bcount]);
_bulletsArray.splice(bcount,1);
removeChild(shipArray[i]);
shipArray.splice(i,1);
}
}
}
}
在此之前,我还有一个射击功能,可以发射子弹并将它们放入 _bulletsArray。
当痕迹出现时,它会显示: 当我不射击子弹时,它给了我这个
_bulletsArray length: 0
bcount: 0
当我拍摄时它给了我这个:
bcount: 0
_bulletsArray length: 1
或
bcount: 0
_bulletsArray length: 2
那么为什么当 _bulletsArray 改变时 bcount 不改变,当我在 for (var bcount= _bulletsArray.length-1; bcount >= 0; bcount--) { 中告诉它这样做时
更糟糕的是 - 当我将“bcount”数据类型为数字“bcount:Number”时,它给了我 NaN
【问题讨论】:
标签: actionscript-3 flash