【发布时间】:2011-08-18 16:08:31
【问题描述】:
请帮忙!我试图从天空中一个接一个地生成 5 个球,并让它们在它们落地或击中地面上另一个用户控制的物体时立即消失。好消息是我可以按预期成功生成球,但是当它们撞到地面(或地面上的其他用户控制对象)时,它们不会消失。自过去 2 天以来,我一直在浏览大量示例代码,但我不知道该怎么做。游戏运行,但调试终端给我一个错误说:运行时错误 - 尝试索引全局 'self' 。这是源代码:
local randomBall = function()
ball = display.newImage( "hardball.png" )
ball.x = math.random (30, 450); ball.y = -20
physics.addBody( ball, { density=2.9, friction=0.5, bounce=0.7, radius=24 } )
local function whenHit (event)
if(event.phase == "began") then
self:removeSelf()
end
end
ball:addEventListener("collision", whenHit)
end
timer.performWithDelay( 500, randomBall, 5 )
【问题讨论】:
标签: iphone ios physics collision coronasdk