Difference between revisions of "Accelerometer"

From GiderosMobile
m (Text replacement - "<source" to "<syntaxhighlight")
Line 10: Line 10:
  
 
=== <translate>Example</translate> ===
 
=== <translate>Example</translate> ===
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
local filter = 0.03
 
local filter = 0.03
 
local fx, fy, fz = 0, 0, 0
 
local fx, fy, fz = 0, 0, 0

Revision as of 16:58, 12 July 2023


Supported platforms: Platform android.pngPlatform ios.pngPlatform winrt.png
Available since: Gideros 2012.8
Inherits from: Object

Description

The Accelerometer class is used to access accelerometer data.

Example

<syntaxhighlight lang="lua"> local filter = 0.03 local fx, fy, fz = 0, 0, 0 --create instance local accelerometer = Accelerometer.new() --start receiving data accelerometer:start()

function onEnterFrame(event) ---get values for example on each enter frame event local x, y, z = accelerometer:getAcceleration() fx = x * filter + fx * (1 - filter) fy = y * filter + fy * (1 - filter) fz = z * filter + fz * (1 - filter) print("Y: "..math.floor(fy*90*-1)) print("X: "..math.floor(fx*90*-1)) print("Z: "..math.floor(fz*90*-1)) end stage:addEventListener("enterFrame",onEnterFrame,self) </source>

Methods

Accelerometer.isAvailable is the accelerometer available?
Accelerometer.new creates new Accelerometer instance

Accelerometer:getAcceleration returns the 3-axis acceleration measured by the accelerometer
Accelerometer:start starts accelerometer updates
Accelerometer:stop stops accelerometer updates

Events

Constants