Difference between revisions of "Accelerometer"

From GiderosMobile
m (fixed some typo)
Line 5: Line 5:
 
'''<translate>Available since</translate>:''' Gideros 2012.8<br/>
 
'''<translate>Available since</translate>:''' Gideros 2012.8<br/>
 
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/Object|Object]]<br/>
 
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/Object|Object]]<br/>
 +
 
=== <translate>Description</translate> ===
 
=== <translate>Description</translate> ===
<translate><br />
+
<translate>The [[Special:MyLanguage/Accelerometer|Accelerometer]] class is used to access accelerometer data.<br/></translate>
The [[Special:MyLanguage/Accelerometer|Accelerometer]] class is used to access accelerometer data. <br />
+
 
<br /></translate>
 
 
=== <translate>Examples</translate> ===
 
=== <translate>Examples</translate> ===
 
'''Example'''<br/>
 
'''Example'''<br/>
Line 31: Line 31:
 
stage:addEventListener("enterFrame",onEnterFrame,self)
 
stage:addEventListener("enterFrame",onEnterFrame,self)
 
</source>
 
</source>
 +
 
{|-
 
{|-
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
  
 
=== <translate>Methods</translate> ===
 
=== <translate>Methods</translate> ===
[[Special:MyLanguage/Accelerometer.isAvailable|Accelerometer.isAvailable]] ''<translate>does the accelerometer available?</translate>''<br/><!-- GIDEROSMTD:Accelerometer.isAvailable() does the accelerometer available? -->
+
[[Special:MyLanguage/Accelerometer.isAvailable|Accelerometer.isAvailable]] ''<translate>is the accelerometer available?</translate>''<br>
[[Special:MyLanguage/Accelerometer.new|Accelerometer.new]] ''<translate>Creates new Accelerometer instance</translate>''<br/><!-- GIDEROSMTD:Accelerometer.new() Creates new Accelerometer instance -->
+
<!-- GIDEROSMTD:Accelerometer.isAvailable() Is the accelerometer available? -->
[[Special:MyLanguage/Accelerometer:getAcceleration|Accelerometer:getAcceleration]] ''<translate>returns the 3-axis acceleration measured by the accelerometer</translate>''<br/><!-- GIDEROSMTD:Accelerometer:getAcceleration() returns the 3-axis acceleration measured by the accelerometer -->
+
[[Special:MyLanguage/Accelerometer.new|Accelerometer.new]] ''<translate>creates new Accelerometer instance</translate>''<br/>
[[Special:MyLanguage/Accelerometer:start|Accelerometer:start]] ''<translate>starts accelerometer updates</translate>''<br/><!-- GIDEROSMTD:Accelerometer:start() starts accelerometer updates -->
+
<!-- GIDEROSMTD:Accelerometer.new() Creates new Accelerometer instance -->
[[Special:MyLanguage/Accelerometer:stop|Accelerometer:stop]] ''<translate>starts accelerometer updates</translate>''<br/><!-- GIDEROSMTD:Accelerometer:stop() starts accelerometer updates -->
+
[[Special:MyLanguage/Accelerometer:getAcceleration|Accelerometer:getAcceleration]] ''<translate>returns the 3-axis acceleration measured by the accelerometer</translate>''<br/>
 +
<!-- GIDEROSMTD:Accelerometer:getAcceleration() returns the 3-axis acceleration measured by the accelerometer -->
 +
[[Special:MyLanguage/Accelerometer:start|Accelerometer:start]] ''<translate>starts accelerometer updates</translate>''<br/>
 +
<!-- GIDEROSMTD:Accelerometer:start() starts accelerometer updates -->
 +
[[Special:MyLanguage/Accelerometer:stop|Accelerometer:stop]] ''<translate>stops accelerometer updates</translate>''<br/>
 +
<!-- GIDEROSMTD:Accelerometer:stop() starts accelerometer updates -->
 +
 
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
 +
 
=== <translate>Events</translate> ===
 
=== <translate>Events</translate> ===
 
=== <translate>Constants</translate> ===
 
=== <translate>Constants</translate> ===
 +
 
|}
 
|}

Revision as of 11:04, 1 December 2019


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.

Examples

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 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