Search code examples
luacoronasdkaccelerometer

Corona SDK - frame-by-frame animation and accelerometer problem


we are doing a game with moving objects around frame-by-frame and also using accelerometer.

We have hooked on two events - about drawing the frame and for the acc.

The problem is, after we receive the acc event, we immediately put the x value in a variable.

Then we use this variable to move an object on the screen, but there is CONSIDERABLE slow down. ( I turn the phone, and after a second the object is moving properly, but a second is just way too much for a game, I expect immediate response).

What am I doing wrong? Is there another workaround to do this, or can I give some params to the accelerometer?

Unfortunately this is a serious problem - a real blocker. If this does not work, I have to find another solution (not Corona) for implementing the game.

Thanks in advance!!! Danail

PS: here's some source:

local lastXGravity = 0

local function move(event) 
        eventTime=event.time
        elapsedTime = eventTime - lastDrawTime
        lastDrawTime = eventTime

        xSpeed = lastXGravity
        local xMoved = xSpeed * elapsedTime
        object.x= object.x + xMoved
end

function acc(event)   
        lastXGravity = event.xGravity
end

Runtime:addEventListener("accelerometer", acc)
Runtime:addEventListener( "enterFrame", move )

Solution

  • The guys at Ansca's forum just got this out:

    system.setAccelerometerInterval( 50 )
    

    This didn't quite actually did the trick, but

    system.setAccelerometerInterval( 100 ) -- warning - battery drainer!!

    did it :)