【发布时间】:2014-12-08 16:51:10
【问题描述】:
当与物体发生碰撞时,我正在尝试改变场景。仅供参考,当我在按钮上使用监听器时,效果很好!场景打扫干净了,“物理”也没有问题了。
场景: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(),我有这个错误:
错误:在解决冲突之前无法翻译对象
我在我的“英雄”和 start_point(在目标场景中)的 Physics.addbody 中添加了一个计时器,但仍然出现此错误:
错误:当世界被锁定时,physics.addBody() 不能被调用 在数字运算的中间,例如在碰撞事件期间
有什么建议吗?
【问题讨论】:
-
抛出的lua错误是哪一行。这只是意味着将
nil的值与数字 (?) 进行比较。