Difference between revisions of "Accelerometer"

From GiderosMobile
Line 6: Line 6:
 
The `Accelerometer` class is used to access accelerometer data. <br />
 
The `Accelerometer` class is used to access accelerometer data. <br />
 
<br />
 
<br />
 +
=== Examples ===
 +
'''Example'''<br/>
 +
<source lang="lua">--create instance
 +
local accelerometer = Accelerometer.new()
 +
--start receiving data
 +
accelerometer:start()
 +
---get values for example on each enter frame event
 +
local x, y, z = accelerometer:getAcceleration()
 +
print(x, y, z)
 +
 +
--once you don't need it, stop it
 +
accelerometer:stop()</source>
 
{|-
 
{|-
 
| style="width: 50%;"|
 
| style="width: 50%;"|

Revision as of 10:39, 23 August 2018

Supported platforms: android, ios
Available since: Gideros 2012.8

Description


The `Accelerometer` class is used to access accelerometer data.

Examples

Example

--create instance
local accelerometer = Accelerometer.new()
--start receiving data
accelerometer:start()
---get values for example on each enter frame event
local x, y, z = accelerometer:getAcceleration()
print(x, y, z)

--once you don't need it, stop it
accelerometer:stop()

Methods

Accelerometer.isAvailable - Accelerometer - does the accelerometer available?
Accelerometer.new - Creates new Accelerometer instance
Accelerometer:getAcceleration - Accelerometer - returns the 3-axis acceleration measured by the accelerometer
Accelerometer:start - Accelerometer - starts accelerometer updates
Accelerometer:stop - Accelerometer - starts accelerometer updates

Events

Constants