Hi. I’m using the accelerometer to add a certain depth to the parallax or background image. The only problem is that I can’t get the original image centered, even after adding a variable for calibration. Here’s the code. I hope someone can help.
-- Local variables local yGravity, yCalibrate = 0, 0 local mvtCof = 48 -- Function to obtain accelerometer data local function onAccelerometer( event ) yGravity = event.yGravity if math.abs(event.yInstant) \>= 0.25 then yCalibrate = yGravity end end -- Function to tilt background local function onTilt( event ) background.y = centerY + (yGravity \* mvtCof) - (yCalibrate \* mvtCof) end -- Add event listeners Runtime:addEventListener( "enterFrame", onTilt ) Runtime:addEventListener( "accelerometer", onAccelerometer )
The image should be centered. However, there’s always like a 20 pixel difference, like 264 instead of 284 as a Y coordinate.