Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]

Slight Offset with Accelerometer
Started by jjsanchezramirez Jan 10 2015 11:55 PM

No replies to this topic
This topic has been archived. This means that you cannot reply to this topic.
[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Observer

  • 18 posts
  • Corona SDK

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

	-- Function to tilt background
	local function onTilt( event )
		background.y = centerY + (yGravity * mvtCof) - (yCalibrate * mvtCof)

	-- 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.