Last active
December 23, 2015 03:29
-
-
Save Partysun/6573650 to your computer and use it in GitHub Desktop.
How to work with Gyroscope or Accelerometer in OpenFL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Imports part... | |
#if mobile | |
import openfl.ui.Accelerometer; | |
#end | |
// Class var part... | |
public static var accelX:Float; | |
public static var accelY:Float; | |
public static var accelZ:Float; | |
// Update loop part... | |
#if mobile | |
var data = Accelerometer.get(); | |
#if android | |
accelX = data.x; | |
accelY = data.y; | |
accelZ = data.z; | |
//iOS | |
#else | |
accelX = -data.x; | |
accelY = -data.y; | |
accelZ = -data.z; | |
#end | |
// Example of usage: | |
// var epsilan:Float = 0.8 | |
// if (roundDecimal(accelY, 4) < epsilan && roundDecimal(accelY, 4) > -epsilan) | |
// accelPos = STEDY; | |
// if (roundDecimal(accelY, 4) > epsilan) | |
// accelPos = LEFT; | |
// if (roundDecimal(accelY, 4) < epsilan) | |
// accelPos = RIGHT; | |
#end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment