Egret:重力感应

来源:互联网 发布:java集合类特点 编辑:程序博客网 时间:2024/05/17 08:47


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

原创粉丝点击