我有以下场景:
我想用重力移动球,所以我写了以下内容:
function onTilt( event )
deltaDegreesXText.text = "xG: " .. (9.8*event.xGravity)
deltaDegreesYText.text = "yG: " .. (-9.8*event.yGravity)
if(ball.isAwake==true)then
fallAsleepText.text = "True "
elseif(ball.isAwake==false)then
fallAsleepText.text = "False "
end
physics.setGravity( ( 9.8 * event.xGravity ), ( -9.8 * event.yGravity ) )
end
问题是,在几秒钟后,球对象会进入睡眠状态并且不再移动。在代码的乞讨中,我有以下几点:
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
system.setIdleTimer( false )
local physics = require "physics"
local physicsData = (require "myphysics").physicsData(1.0)
physics.start( true)
任何想法都会出错?为什么physics.start(noSleep)不起作用或我如何阻止球落入睡眠状态?
答案 0 :(得分:0)
body.isSleepingAllowed = false;
答案 1 :(得分:0)
是的,我试过了,在开始时它没有用。最后问题是我写道:
ball.isSleepingAllowed = false
physics.addBody (ball, physicsData:get("ball"))
但正确的是:
physics.addBody (ball, physicsData:get("ball"))
ball.isSleepingAllowed = false
我应首先将物理学添加到球中然后body.isSleepingAllowed = false;
相反的方法不起作用。