Difference between revisions of "Accelerometer"

From GiderosMobile
m (----)
 
(23 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
 
<languages />
 
 
 
<!-- GIDEROSOBJ:Accelerometer -->
 
<!-- GIDEROSOBJ:Accelerometer -->
 
'''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform winrt.png]]<br/>
 
'''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/>
'''Inherits from:''' [[Special:MyLanguage/Object|Object]]<br/>
+
'''Inherits from:''' [[Object]]<br/>
  
 
=== Description ===
 
=== Description ===
The [[Special:MyLanguage/Accelerometer|Accelerometer]] class is used to access accelerometer data.
+
The Accelerometer class is used to access accelerometer data.
<br/>
 
  
=== Examples ===
+
=== Example ===
<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
Line 22: Line 18:
  
 
function onEnterFrame(event)
 
function onEnterFrame(event)
        ---get values for example on each enter frame event
+
---get values for example on each enter frame event
 
local x, y, z = accelerometer:getAcceleration()
 
local x, y, z = accelerometer:getAcceleration()
fx = x * filter + fx * (1 - filter)
+
fx = x * filter + fx * (1 - filter)
fy = y * filter + fy * (1 - filter)
+
fy = y * filter + fy * (1 - filter)
fz = z * filter + fz * (1 - filter)
+
fz = z * filter + fz * (1 - filter)
 
print("Y: "..math.floor(fy*90*-1))
 
print("Y: "..math.floor(fy*90*-1))
 
print("X: "..math.floor(fx*90*-1))
 
print("X: "..math.floor(fx*90*-1))
Line 32: Line 28:
 
end
 
end
 
stage:addEventListener("enterFrame",onEnterFrame,self)
 
stage:addEventListener("enterFrame",onEnterFrame,self)
</source>
+
</syntaxhighlight>
<br/>
 
  
 
{|-
 
{|-
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
 +
=== Methods ===
 +
[[Accelerometer.isAvailable]] ''is the accelerometer available?''<br><!--GIDEROSMTD:Accelerometer.isAvailable() is the accelerometer available?-->
 +
[[Accelerometer.new]] ''creates a new Accelerometer instance''<br/><!--GIDEROSMTD:Accelerometer.new() creates a new Accelerometer instance-->
  
=== Methods ===
+
[[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.isAvailable|Accelerometer.isAvailable]] ''is the accelerometer available?''<br>
+
[[Accelerometer:start]] ''starts accelerometer updates''<br/><!--GIDEROSMTD:Accelerometer:start() starts accelerometer updates-->
[[Special:MyLanguage/Accelerometer.new|Accelerometer.new]] ''creates new Accelerometer instance''<br/>
+
[[Accelerometer:stop]] ''stops accelerometer updates''<br/><!--GIDEROSMTD:Accelerometer:stop() stops accelerometer updates-->
[[Special:MyLanguage/Accelerometer:getAcceleration|Accelerometer:getAcceleration]] ''returns the 3-axis acceleration measured by the accelerometer''<br/>
 
[[Special:MyLanguage/Accelerometer:start|Accelerometer:start]] ''starts accelerometer updates''<br/>
 
[[Special:MyLanguage/Accelerometer:stop|Accelerometer:stop]] ''stops accelerometer updates''<br/>
 
  
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
 
 
=== Events ===
 
=== Events ===
 
=== Constants ===
 
=== Constants ===
Line 52: Line 46:
 
|}
 
|}
  
----
+
<!--{{Accelerometer}}-->
 
+
{{GIDEROS IMPORTANT LINKS}}
{{Special:PrefixIndex/Accelerometer}}
 

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