当物体与物体发生碰撞时,我试图改变场景。只是为了得到信息,当我在按钮上使用一个侦听器时,它工作得很好!现场最清洁,没有问题的“物理”了。
场景: CH1-SAH-A01
function onCollision(event)
if (event.phase=="began") then
if (event.object1.myName=="hero" and event.object2.myName=="start_point") then
composer.gotoScene("CH1-SPR-A01", "fade", 500)
end
elseif (event.phase=="ended") then
if (event.object1.myName=="hero" and event.object2.myName=="ground") then
end
end
end我从这里开始物理学:
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中添加了一个计时器到我的“英雄”和start_point (在目标场景中),并且仍然有以下错误:
错误:当世界被锁定并在数字处理过程中(例如在碰撞事件中)时,无法调用physics.addBody()
有什么建议吗?
发布于 2014-12-07 11:31:38
在日冕中,在碰撞结束之前,你不能改变与碰撞有关的物体的任何东西。此外,在冲突正在进行时,不能调用physics.stop()。您需要在更改场景之前使用timer.performWithDelay ()标志或延迟,直到冲突结束为止。
这将在此链接中的“重要”部分中介绍:http://docs.coronalabs.com/daily/guide/physics/collisionDetection/index.html
https://stackoverflow.com/questions/27319627
复制相似问题