shake to switch between 2 screens

Hi All,

I am a little stuck here, hope I could get some help.

I am trying to use director class and event.shake to switch between 2 screens. I have used the following code.

local function changeHours ( event )  
 if event.isShake == true then  
 director:changeScene("mainEng")  
 end  
 end  
  
Runtime:addEventListener("accelerometer",changeHours)  

This works to change the scene, but when I try to shake to switch back it does not work. I have tried cleaning the runtime listeners but it still does not work.

Many thanks
Chris [import]uid: 10697 topic_id: 10496 reply_id: 310496[/import]

Try this…

local function changeHours ( event )  
 if event.isShake == true then  
 Runtime:removeEventListener("accelerometer",changeHours)  
 director:changeScene("mainEng")  
 end  
 end  
   
Runtime:addEventListener("accelerometer",changeHours)  

Think that should be right. [import]uid: 26801 topic_id: 10496 reply_id: 41075[/import]

Hi there,
i’ve got a similar problem with director, with accelerometer.
When i change scene, it don’t work anymore, saying: “attempt to call method ‘applyLinearImpulse’ (a nil value)”

here is the code:
[lua]local function onAccelerate( event )
if event.isShake == true then
sangle = ((math.random (-5, 5))/100)
ball_f:applyLinearImpulse( sangle, -0.3, ball_f.x, ball_f.y )
print (sangle)
end
end
Runtime:addEventListener (“accelerometer”, onAccelerate)[/lua]

i clean the listener when i exit:
[lua]local function menugame()
Runtime:removeEventListener(“accelerometer”,onAccelerate)
Runtime:removeEventListener(“enterFrame”, followFunction)
Runtime:removeEventListener(“enterFrame”, gameLoop)
TextCandy.CleanUp()
director:changeScene(“menu”)
end[/lua]
but it don’t work… :frowning:

of course it works when i insert the “Runtime:removeEventListener(“accelerometer”,onAccelerate)” in the onAccelerate function, but then i can “bump” my ball only once, so it’s not the point…
any ideas what is wrong? [import]uid: 44010 topic_id: 10496 reply_id: 64614[/import]

problem solved: changed “local function onAccelerate( event )” to “function onAccelerate( event )” [import]uid: 44010 topic_id: 10496 reply_id: 64629[/import]