Frame-by-frame game and accelerometer problem

Hi guys,

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 for implementing the game.

Thanks in advance!!!
Danail

[import]uid: 57961 topic_id: 11882 reply_id: 311882[/import]

@daniel,
If you have a headache have an asprin, that could be the most generic advice. On these forums there are so many users that ask questions to be resolved, without outlining what they are doing, that can be highlighted for errors.

Now, there are games where the accelerometer works perfectly fine and responsive made with CoronaSDK.

I feel that if you want a resolution for your issue, it would be best that you post the code you are using that does not work for you.

You do not want responses from others that state “But It works for me”, do you?

So when you want medical advice, you need to let the doctor examine, you cannot get a detailed diagnosis by narrating your issues on the phone.

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 11882 reply_id: 43313[/import]

+1 on jayantv’s advice.

you really need to post your code for us to help you. [import]uid: 48521 topic_id: 11882 reply_id: 43332[/import]

Ok, you are right!

here’s a very small piece:

[lua]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 )[/lua]

The result on the device is: I turn the phone on one side, the object FIRST slows down its speed, then starts going in the direction I want, which is ok, but it takes almost a second! I’m describing this behaviour for android, on a good phone.

I really hope I’m doing something wrong!

Thanks again
Danail [import]uid: 57961 topic_id: 11882 reply_id: 43345[/import]

danaildelchev,
from the first glance, all I can say is that it is look for the values of xMoved. That might be very very small thereby causing the object to move very slow.

Try replacing
object.x = object.x + xMoved
to
object.x = object.x + 1 --try to increase to get an acceptable movement first

I know you are trying to get the resolution for skipped frames, but if that is fast enough then fine otherwise you have to spike up the movement by a factor that works for you as acceptable.

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 11882 reply_id: 43356[/import]

It’s actually moving quite good, when you give enough time for the accelerometer to put the right values.

It’s moving fine, because I multiply it by the MILLISECONDS passed by the last frame.

The max value for the accelerometer is around 9.8, and it usually is around 1.

1 * passedMilliseconds = enough pixels for one frame (30-60, more…)

The problem is not the speed of the object, but the responsiveness. Try games like doodle jump, abduction on android, you’ll see that in the moment you turn the phone, the character is turning.

This is not the case with my object, where it first slows down the initial speed, then begans turning and accelerating to its xSpeed… [import]uid: 57961 topic_id: 11882 reply_id: 43362[/import]

Try that one…

[lua]system.setAccelerometerInterval( 50 )
local lastXGravity = 0

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

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 )[/lua] [import]uid: 10478 topic_id: 11882 reply_id: 43366[/import]

YES!

Thank you very much!!! The 50 value did not quite do it, but with 100 is quite perfect!!

Thanks PixelEnvision! [import]uid: 57961 topic_id: 11882 reply_id: 43371[/import]

You’re welcome :slight_smile:

Btw, 100 Hz is the max value and it’s not easy on the battery usage…

Of course it’s fully valid and useable but I would suggest lowering it a bit as long as it keeps the responsiveness you’re after… [import]uid: 10478 topic_id: 11882 reply_id: 43382[/import]

Yes, we will test different values for that, thanks. I know it’s quite on the draining side, but it gets the results we need. [import]uid: 57961 topic_id: 11882 reply_id: 43383[/import]