在Corona中移除移动对象

我试图在触摸时移除 heli 对象。但当我触摸它时它并没有消失。如何确保触摸的对象消失?

点赞
用户2524586
用户2524586

应该是_touch_而不是_onTouch_:

heli.touch = touchpop
heli:addEventListener( "touch", heli )

这是另一个我更喜欢的工作版本:

function touchpop( event )
    -- 现在我们没有self了,而是使用event.target
    local self = event.target
    if(event.phase == "began") then
        self:removeSelf( )
    end
    return true
end

-- 在这里我们需要将函数添加为第二个参数
heli:addEventListener( "touch", touchpop )

更多信息: https://docs.coronalabs.com/api/event/touch/index.html

2015-12-20 05:40:37