更改碰撞时的场景-无法删除-scene()perspective.lua:尝试将nil与number进行比较

更改碰撞时的场景-无法删除-scene()perspective.lua:尝试将nil与number进行比较,lua,coronasdk,Lua,Coronasdk,我试图在与物体发生碰撞时改变场景。仅供参考,当我在按钮上使用侦听器时,它工作得很好!场景被清理干净了,不再有“物理”的问题了 场景:CH1-SAH-A01 我从这里开始讲物理: function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is still off scr

我试图在与物体发生碰撞时改变场景。仅供参考,当我在按钮上使用侦听器时,它工作得很好!场景被清理干净了,不再有“物理”的问题了

场景:CH1-SAH-A01

我从这里开始讲物理:

function scene:show( event )

local sceneGroup = self.view
local phase = event.phase

if ( phase == "will" ) then
      -- Called when the scene is still off screen (but is about to come on screen).
    camera:setBounds(display.contentWidth/2,4200-display.contentWidth*0.5,display.contentHeight-1500,-220)
    camera.damping=1
    physics.start()
    camera:track()
    setHeroPropreties()
然后,当场景离开时:

function scene:hide( event )
  local sceneGroup = self.view
  local phase = event.phase    
   if ( phase == "will" ) then        
    timer.performWithDelay( 1000, function() physics.stop();end )
    Runtime:removeEventListener("enterFrame", ShowCharacters)
    Runtime:removeEventListener("collision", onCollision)
    slideOffSensor:removeEventListener( "touch", handleSlideOff )
    composer.removeScene("CH1-SAH-A01")
   elseif ( phase == "did" ) then          

   end
end
销毁功能是:

function scene:destroy( event )

    local sceneGroup = self.view
    local camera = self.view
    package.loaded[physics] = nil
    physics = nil
end
我试图在physics.stop()函数中添加计时器,但没有成功。冲突后,虚拟控制台监视器中存在一些“错误”:

我在当前场景和目标场景中未使用transition.to(),我发现以下错误:

错误:在解决碰撞之前无法平移对象

我在physics.addbody中为我的“英雄”和起点(在目标场景中)添加了一个计时器,但仍然存在以下错误:

错误:当世界被锁定并关闭时,无法调用physics.addBody() 在数字压缩过程中,例如碰撞事件


有什么建议吗?

在corona中,在碰撞结束之前,您不能更改与碰撞有关的对象的任何信息。此外,当碰撞正在进行时,不能调用physics.stop()。在更改场景之前,需要使用timer.performWithDelay()的标志或延迟,直到碰撞结束

本链接的“重要”部分介绍了这一点:

抛出的lua错误是哪一行。这只意味着一个
nil
的值将与一个数字(?)进行比较。
function scene:destroy( event )

    local sceneGroup = self.view
    local camera = self.view
    package.loaded[physics] = nil
    physics = nil
end