【发布时间】:2013-10-30 09:50:20
【问题描述】:
我正在使用 Corona SDK 在 Lua 中编写代码,我希望在碰撞后使对象处于非活动状态。
function onCollision(event)
if event.phase == "began" then
bullet.collided = true
bullet.isVisible = false
bullet:applyLinearImpulse(-5, 0, bullet.x, bullet.y)
explode(event)
end
end
function explode(event)
local x = event.object2.x
local y = event.object2.y
explosion.x = x
explosion.y = y
explosion.isVisible = true
explosion:play()
resetExplosion()
end
上述函数获取屏幕上的单个子弹,并在与它在 y 轴上射出的球碰撞后使其不可见。然后它会施加一个脉冲以将其从 x 轴的屏幕上移除。我的问题是碰撞中的球(object2)在碰撞后也是不可见的,但它仍然可以被新子弹击中。只有一个子弹,所以我可以直接说bullet.whatever,但是有一系列球,所以球必须像ball[i].whatever一样被寻址。 有没有办法通过 onCollision 函数传递索引?
【问题讨论】: