physics and storyboard problem

Hi,

my game have 2 scenes which could be switched by storyboard.
the 2 scenes have different physics gravity settings.
before I gotoScene 2 form scene 1, I pause() the physics first ( the physics is a global var ).
scene 2’s gravity is tilt based.
before I switch back to scene 1 from scene 2, I pause the physics again and remove the listener for “accelerometer”.
but when I come back to scene 1, the physics gravity seems messed up. the “accelerometer” still works.

also please tell me what’s the different between physics.stop() and physics.pause() ?
because I first tried physics.stop() instead of pause() when switching scenes, but it didn’t work.

thanks a lot! [import]uid: 99926 topic_id: 22605 reply_id: 322605[/import]

So it sounds like the accelerometer listener maybe isn’t being removed properly; is that it? Or it isn’t being removed but also gravity is “weird” in a way other than still adjusting based on tilt? [import]uid: 52491 topic_id: 22605 reply_id: 90430[/import]

Hi,

I found that for storyboard I must remove listeners in the function scene:exitScene( event ), not in my local function onTouch(event).

back to scene 1 then the accelerometer event is no longer listened!

now I only have one problem, I still get weird gravity in scene 2,

onTilt = function(event)
physics.setGravity( 50 * event.xGravity, -50 * event.yGravity )
debug_text.text = event.xGravity
end

this function is in function scene:createScene( event ), maybe I shouldn’t define this function in function scene:createScene( event )?

seems I always get a negative xgravity, it’s like every body is pulled to the left side of the screen.

by the way my scene 1 does have a negative x gravity, but before I switch to scene 2 I pause the physics(the global var) and in scene 2 I physics.start(), and set the gravity listen to onTilt. [import]uid: 99926 topic_id: 22605 reply_id: 90435[/import]

Use a print statement to see what the xGravity is doing is my advice in this situation; is it reacting at all? If they always go left regardless of tilt it sounds like there may be an issue in the function or listener.

(I see you are displaying xGravity somewhere with your code, assuming that is still the case you could use that rather than a print statement - but what value is being returned?) [import]uid: 52491 topic_id: 22605 reply_id: 90445[/import]

Hi,

thanks for reply!
the xGravity’s value changs between -0.9 and 0.3/0.4.
it’s like there is a force pulling things to screen left.

I used debug_text to show the xGravity because I can’t test accelerator gravity in simulator. :slight_smile:

maybe I should isolate the code then test…

:slight_smile: [import]uid: 99926 topic_id: 22605 reply_id: 90874[/import]

You can test it if you grab the Corona remote app - great third party tool, I love it - maybe try that? :slight_smile:

Else, yes, isolating code then testing it the way most things get solved :wink: [import]uid: 52491 topic_id: 22605 reply_id: 90918[/import]