本文主要是介绍Egret:重力感应,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
class MotionExample extends egret.DisplayObjectContainer {label: egret.TextField;motion: egret.Motion;constructor() {super();//文本框this.label = new egret.TextField();this.label.y = 400;this.label.x = 50;this.addChild(this.label);// 关键代码开始this.motion = new egret.Motion();this.motion.addEventListener(egret.Event.CHANGE,this.onMotion,this);this.motion.start(); // 开始监听设备运动状态// stop ( ):void 停止监听设备运动状态}onMotion(e:egret.MotionEvent){this.label.text = "加速度: \n:" + e.accelerationIncludingGravity.x + ",\n:" + e.accelerationIncludingGravity.y + ",\nz:" + e.accelerationIncludingGravity.z;// 关键代码结束if(e.accelerationIncludingGravity.y > 0){this.label.y--;}if(e.accelerationIncludingGravity.y < 0){this.label.y++;}}
}
转自:
http://blog.csdn.net/Miss_Luyou/article/details/53884125?locationNum=4&fps=1
这篇关于Egret:重力感应的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!