Difference between revisions of "Gyroscope"

From GiderosMobile
Line 3: Line 3:
 
'''Available since:''' Gideros 2012.8<br/>
 
'''Available since:''' Gideros 2012.8<br/>
 
=== Description ===
 
=== Description ===
<br />
+
<translate><br />
The `Gyroscope` class is used to access gyroscope data. <br />
+
The [[[Gyroscope]]] class is used to access gyroscope data. <br />
<br />
+
<br /></translate>
 
=== Examples ===
 
=== Examples ===
 
'''Example'''<br/>
 
'''Example'''<br/>
<source lang="lua">local gyroscope = Gyroscope.new()<br />
+
<source lang="lua">local gyroscope = Gyroscope.new()
gyroscope:start()<br />
+
gyroscope:start()
<br />
+
 
local angx = 0<br />
+
local angx = 0
local angy = 0<br />
+
local angy = 0
local angz = 0<br />
+
local angz = 0
local function onEnterFrame(event)<br />
+
local function onEnterFrame(event)
local x, y, z = gyroscope:getRotationRate()<br />
+
local x, y, z = gyroscope:getRotationRate()
<br />
+
angx = angx  x * event.deltaTime<br />
+
angx = angx  x * event.deltaTime
angy = angy  y * event.deltaTime<br />
+
angy = angy  y * event.deltaTime
angz = angz  z * event.deltaTime<br />
+
angz = angz  z * event.deltaTime
<br />
+
print(angx * 180 / math.pi, angy * 180 / math.pi, angz * 180 / math.pi)<br />
+
print(angx * 180 / math.pi, angy * 180 / math.pi, angz * 180 / math.pi)
end<br />
+
end
<br />
+
 
 
stage:addEventListener(&quot;enterFrame&quot;, onEnterFrame)</source>
 
stage:addEventListener(&quot;enterFrame&quot;, onEnterFrame)</source>
 
{|-
 
{|-

Revision as of 14:34, 23 August 2018

Supported platforms: android, ios
Available since: Gideros 2012.8

Description


The [[[Gyroscope]]] class is used to access gyroscope data.

Examples

Example

local gyroscope = Gyroscope.new()
gyroscope:start()

local angx = 0
local angy = 0
local angz = 0
local function onEnterFrame(event)
	local x, y, z = gyroscope:getRotationRate()
		
	angx = angx   x * event.deltaTime
	angy = angy   y * event.deltaTime
	angz = angz   z * event.deltaTime
		
	print(angx * 180 / math.pi, angy * 180 / math.pi, angz * 180 / math.pi)
end

stage:addEventListener(&quot;enterFrame&quot;, onEnterFrame)

Methods

Gyroscope.isAvailable - Gyroscope - does the gyroscope available?
Gyroscope.new - Creates new Gyroscope instance
Gyroscope:getRotationRate - Gyroscope - returns the rotation rate in radians per second
Gyroscope:start - Gyroscope - starts gyroscope updates
Gyroscope:stop - Gyroscope - stops gyroscope updates

Events

Constants