physics.start( noSleep ) doesn't seem to work

I have the following scene.

2yy47j4.jpg

I want to move the ball using gravity so I wrote the following:

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  

The problem is that after some seconds the ball object fall sleep and do not move any more. In the begging of the code I have the following:

whchmx.jpg
 

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 )

Any idea whats going wrong?

You need to write physics.start(true), not physics.start(noSleep), to disable sleeping.

  • Andrew

I did that but still the problem remains

In that case, try setting the isSleeepingAllowed property on the ball to false (http://docs.coronalabs.com/api/type/Body/isSleepingAllowed.html).  That should definitely stop it from sleeping.

  • Andrew

Still the problem remains, here is how is initialize the ball:

 

 ball=display.newImage("ball1.png") ball.x=30 ball.y=display.contentCenterY ball.name="ball" ball.isSleepingAllowed = false

any idea whats going wrong?

You have to add the isSleepingAllowed property only after you declare the ball as a physics object.  Above, you’re adding that property before you make the ball a physics object.

  • Andrew

Thank you so much, finally it works, you save my day, thx.

You need to write physics.start(true), not physics.start(noSleep), to disable sleeping.

  • Andrew

I did that but still the problem remains

In that case, try setting the isSleeepingAllowed property on the ball to false (http://docs.coronalabs.com/api/type/Body/isSleepingAllowed.html).  That should definitely stop it from sleeping.

  • Andrew

Still the problem remains, here is how is initialize the ball:

 

 ball=display.newImage("ball1.png") ball.x=30 ball.y=display.contentCenterY ball.name="ball" ball.isSleepingAllowed = false

any idea whats going wrong?

You have to add the isSleepingAllowed property only after you declare the ball as a physics object.  Above, you’re adding that property before you make the ball a physics object.

  • Andrew

Thank you so much, finally it works, you save my day, thx.