Hi all,
Can anybody help me in accelerometer based movement.
I am trying to build brick breaker example myself.
I am tying X coordinate of paddle accoding to X component of gravity vector and using accelerometer event to change the position of the paddle but the paddle motion is not smooth. It’s kind of jerky.
Wondering if there is better way to do this?
Things that I think can be causing this are that accelerometer event is not fired as frequently as it should to get smooth motion, but I don’t know how to check that.
A solution I am thinking of is instead of tying X coordinate of the paddle to the gravity vector’s X component, I give velocity to paddle using gravity vector, but I am work right now so can’t test it until tonight when I go home.
Following is my code to change paddle position
[lua]local _w = display.contentWidth
local _h = display.contentHeight
local wBar = 80
local hBar = 15
local bar = display.newImage(‘h_paddle.png’,(_w-wBar)*0.5,_h-hBar)
physics.addBody(bar, “static”, { density=1, friction=0, bounce=1 } )
local function updateAccelerometer(e)
local xGravity = e.xGravity
local x = _w*0.5 + (_w*0.5 * (xGravity*4))
if ((x - wBar*0.5)<0) then
x = wBar*0.5
elseif ((x + wBar*0.5)>_w) then
x = _w - wBar*0.5
end
bar.x = x
end
Runtime:addEventListener( “accelerometer” , updateAccelerometer )[/lua] [import]uid: 48521 topic_id: 8870 reply_id: 308870[/import]
