我有一个游戏/物理原型,在100次中看起来很好。但每次经常在“重置”级别(当使用启动时),立即收集玩家站在起点我不指望。物理暂停,玩家身体此时也“无效”,为什么在重置阶段会发生碰撞。
问题:下面的“重置级别”代码阶段是否会发生冲突?想知道是否因为一切都按顺序发生,这是否是一个问题?本节的某些部分是否真的需要“performAfterDelay”。
-- PLAYER IN MOTION
2013-09-10 11:24:56.035 Corona Simulator[6677:707] Player.isBodyActive = true
-- COLLISION OCCURS
2013-09-10 11:24:57.453 Corona Simulator[6677:707] onPlayerCollision:began:
2013-09-10 11:24:57.453 Corona Simulator[6677:707] physics.removeBody(Player)
-- RESET LEVEL HIT (Get collision every so often on restart during this phase, but why?)
2013-09-10 11:25:01.644 Corona Simulator[6677:707] physics.pause()
2013-09-10 11:25:01.645 Corona Simulator[6677:707] physics.addBody( Player, "dynamic") -- add body back
2013-09-10 11:25:01.645 Corona Simulator[6677:707] Player.isBodyActive = false -- make inactive until after motion is started
2013-09-10 11:25:01.645 Corona Simulator[6677:707] physics.start()
我已经使用日志来处理代码,以指示时间......
答案 0 :(得分:0)
更新:想想我拥有它(需要更多测试)但似乎我需要延迟physics.start以允许'Player.isBodyActive = false“生效。现在最后一行:
timer.performWithDelay(100,
function(event)
physics.start()
end
)