当项目命中斯巴达时,我在以下函数中得到一个类型错误(一个术语未定义且没有属性)
子弹是一个数组 斯巴达人是一个数组
这个功能主要是移动子弹和斯巴达人,同时检查它们是否碰撞,以及它们是否都被移除。
function loop(event:Event)
{
for (var bcount=0; bcount < bullets.length; bcount++)
{
if (bullets[bcount].x <= 1055)
{
bullets[bcount].x = bullets[bcount].x + bulletSpeed;
}
else
{
removeChild(bullets[bcount])
bullets.splice(bcount, 1)
bcount--
}
for (var spcount=0; spcount<spartans.length; spcount++)
{
spartans[spcount].x = spartans[spcount].x - spartanSpeed
if (bullets[bcount].hitTestObject(spartans[spcount]))
{
removeChild(spartans[bcount])
spartans.splice(spcount, 1)
spcount--
removeChild(bullets[bcount])
bullets.splice(bcount, 1)
bcount--
}
}
}
}发布于 2013-08-20 12:44:06
First
在第二个循环中,我认为您想要删除spartansspcount。
所以改变这一行
removeChild(spartans[bcount])至
removeChild(spartans[spcount])第二
在第二个循环中,您应该检查bcount是否小于零。因为在第一个循环和第二个循环中,您都减少了bcount,所以bcount可以是-1。
例如,子弹的x大于1055,所以bcount是-1。如果这种情况没有发生,在第二个循环中,如果碰撞在某些时候发生,那么bcount将小于0。
https://stackoverflow.com/questions/18333055
复制相似问题