Difference between revisions of "Accelerometer"

From GiderosMobile
 
(70 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
'''Supported platforms:''' android, ios<br/>
+
<!-- GIDEROSOBJ:Accelerometer -->
 +
'''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform winrt.png]]<br/>
 
'''Available since:''' Gideros 2012.8<br/>
 
'''Available since:''' Gideros 2012.8<br/>
=== {{Description}} ===
+
'''Inherits from:''' [[Object]]<br/>
<translate><br />
+
 
The [[Special:MyLanguage/Accelerometer|Accelerometer]] class is used to access accelerometer data. <br />
+
=== Description ===
<br /></translate>
+
The Accelerometer class is used to access accelerometer data.
=== Examples ===
+
 
'''Example'''<br/>
+
=== Example ===
<source lang="lua">--create instance
+
<syntaxhighlight lang="lua">
 +
local filter = 0.03
 +
local fx, fy, fz = 0, 0, 0
 +
--create instance
 
local accelerometer = Accelerometer.new()
 
local accelerometer = Accelerometer.new()
 
--start receiving data
 
--start receiving data
 
accelerometer:start()
 
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
+
function onEnterFrame(event)
accelerometer:stop()</source>
+
---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)
 +
</syntaxhighlight>
 +
 
 
{|-
 
{|-
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
 
=== Methods ===
 
=== Methods ===
[[Special:MyLanguage/Accelerometer.isAvailable|Accelerometer.isAvailable]] ''<translate>Accelerometer - does the accelerometer available?</translate>''<br/>
+
[[Accelerometer.isAvailable]] ''is the accelerometer available?''<br><!--GIDEROSMTD:Accelerometer.isAvailable() is the accelerometer available?-->
[[Special:MyLanguage/Accelerometer.new|Accelerometer.new]] ''<translate>Creates new Accelerometer instance</translate>''<br/>
+
[[Accelerometer.new]] ''creates a new Accelerometer instance''<br/><!--GIDEROSMTD:Accelerometer.new() creates a new Accelerometer instance-->
[[Special:MyLanguage/Accelerometer:getAcceleration|Accelerometer:getAcceleration]] ''<translate>Accelerometer - returns the 3-axis acceleration measured by the accelerometer</translate>''<br/>
+
 
[[Special:MyLanguage/Accelerometer:start|Accelerometer:start]] ''<translate>Accelerometer - starts accelerometer updates</translate>''<br/>
+
[[Accelerometer:getAcceleration]] ''returns the 3-axis acceleration measured by the accelerometer''<br/><!--GIDEROSMTD:Accelerometer:getAcceleration() returns the 3-axis acceleration measured by the accelerometer-->
[[Special:MyLanguage/Accelerometer:stop|Accelerometer:stop]] ''<translate>Accelerometer - starts accelerometer updates</translate>''<br/>
+
[[Accelerometer:start]] ''starts accelerometer updates''<br/><!--GIDEROSMTD:Accelerometer:start() starts accelerometer updates-->
 +
[[Accelerometer:stop]] ''stops accelerometer updates''<br/><!--GIDEROSMTD:Accelerometer:stop() stops accelerometer updates-->
 +
 
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
 
=== Events ===
 
=== Events ===
 
=== Constants ===
 
=== Constants ===
 +
 
|}
 
|}
 +
 +
<!--{{Accelerometer}}-->
 +
{{GIDEROS IMPORTANT LINKS}}

Latest revision as of 07:57, 4 November 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

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)

Methods

Accelerometer.isAvailable is the accelerometer available?
Accelerometer.new creates a 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