Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

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

No replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

jjsanchezramirez

[GLOBAL: userInfoPane.html]
jjsanchezramirez
  • 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
		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.




[topic_controls]
[/topic_controls]