我試圖在與對象發生碰撞時更改場景。僅供參考,當我在按鈕上使用偵聽器時,效果很好!現場已經清理完畢,「物理」已經沒有問題了。在碰撞時更改場景 - 無法移除場景()perspective.lua:嘗試將nil與數字進行比較
scene : 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(),和我這個錯誤:
ERROR: Cannot translate an object before collision is resolved
我加在physics.addbody一個計時器,我的「英雄」和start_point(在目標場景),並且仍然有這個錯誤:
ERROR: physics.addBody() cannot be called when the world is locked and in the middle of number crunching, such as during a collision event
有什麼建議?
什麼行拋出的LUA錯誤。這只是意味着將一個「nil」的值與一個數字(?)進行比較。 – 2014-12-05 16:45:57