Hi, i have a problem with my hero:removeSelf() for some reason it doesn’t trigger my function Hero:finalize(). I put my hero:removeSelf() in scene:hide()
function scene:hide( event )
if ( event.phase == "will" ) then
hero:removeSelf()
--world = nil
elseif ( event.phase == "did" ) then
Runtime:removeEventListener("enterFrame", enterFrame)
end
end
and this is my finalize
function Hero:finalize()
print("hilang kan")
Hero:removeEventListener( "collision" )
Runtime:removeEventListener( "enterFrame", enterFrame )
Runtime:removeEventListener( "key", key )
end
Did you declare Hero and finalize outside of the scene:create function? If they are local to the scene:create or scene:show function, they will be invisible to scene:hide. Because removeSelf() checks to make sure the object isn’t a nil value before attempting to remove it, it could very well be that Hero is nil for scene:hide, but you’re not getting an error message because removeSelf() is just ignoring it.
Did you attach an event listener to Hero? Hero:addEventListener( "finalize")
Also, the finalize function should be an event: functionHero:finalize( event )