碰撞时改变场景 - 无法移除-scene()perspective.lua:尝试将nil与数字进行比较

我正试图在与物体碰撞时更改场景。仅供参考,当我在按钮上使用监听器时,它可以正常运作!场景被清除,与“物理”没有问题。

场景: CH1-SAH-A01

  函数onCollision(event)
        if (event.phase=="began") then
            if (event.object1.myName=="hero" and event.object2.myName=="start_point") then
                composer.gotoScene("CH1-SPR-A01", "淡出", 500)
            end
        elseif (event.phase=="ended") then
            if (event.object1.myName=="hero" and event.object2.myName=="ground") then
            end
         end
    end

然后我在这里开始物理:

函数场景:显示事件(事件)

local sceneGroup = this.view 
local phase = event.phase
 
如果(阶段==“将”),那么
      --在场景仍不在屏幕上但即将出现时调用。
      camera:setBounds(display.contentWidth/2,4200-display.contentWidth*0.5,display.contentHeight-1500,-220)
      camera.damping=1
      physics.start()
      camera:track()
      setHeroPropreties()

然后,当离开场景时:

函数场景:隐藏(事件)
  
 本地场景组= this.view 
  本地阶段=事件.相位
   如果(阶段==“将”),那么
    计时器.performWithDelay(1000function()物理停止();结尾)
    Runtime:removeEventListener("enterFrame", ShowCharacters)
    Runtime:removeEventListener("collision", onCollision)
    slideOffSensor:removeEventListener( "touch", handleSlideOff )
    composer.removeScene("CH1-SAH-A01")
   elseif(阶段==“完成”)然后
 
   end
end

和毁坏功能是:

函数场景:毁坏(事件)

    本地场景组= this.view 
    本地摄像机= this.view
     package.loaded [physics]=nil
     物理= nil
end

我尝试在physics.stop()函数中添加计时器,但失败了。碰撞后,在虚拟控制台监视器中有一些“错误”:

我当前使用的场景和目标场景中没有使用transition.to(),但仍然出现此错误:

ERROR: Cannot translate an object before collision is resolved

我在目标场景中的“hero”和“start_point”中添加了physics.addbody的计时器,仍然出现此错误:

ERROR: physics.addBody() cannot be called when the world is locked and in the middle of number crunching, such as during a collision event

有什么建议吗?

点赞
用户2393536
用户2393536

在 corona 中,直到碰撞结束,你无法改变与碰撞相关的物体。此外,在碰撞发生时,你无法调用 physics.stop()。在改变场景之前,你需要使用标志或 timer.performWithDelay() 来延迟碰撞结束。 这在此链接的“重要”部分中有所涉及: http://docs.coronalabs.com/daily/guide/physics/collisionDetection/index.html

2014-12-07 11:31:38