egret.Motion
包 egret
接口 public interface Motion
继承 egret.Motion → egret.EventDispatcher → egret.HashObject
Motion 类从用户设备读取运动状态信息并派发 CHANGE 事件。当设备移动时,传感器会检测到此移动并返回设备加速度,重力和旋转数据。@see egret.MotionEventMotion 类提供了 start 和 stop 方法,来启动和停止运动信息检查
公共方法
方法 |
---|
start():void 开始监听设备运动状态 |
stop():void 停止监听设备运动状态 |
事件
Events |
---|
egret.Event.CHANGE 运动状态发生改变 |
方法详细信息
start()
public start():void
开始监听设备运动状态
- 支持版本:Egret 2.4
- 运行平台:Web
stop()
public stop():void
停止监听设备运动状态
- 支持版本:Egret 2.4
- 运行平台:Web
示例
class MotionExample extends egret.DisplayObjectContainer {
label: egret.TextField;
constructor() {
super();
this.label = new egret.TextField();
this.label.y = 50;
this.label.x = 50;
this.addChild(this.label);
var motion = new egret.Motion();
motion.addEventListener(egret.Event.CHANGE,this.onMotion,this);
motion.start();
}
onMotion(e:egret.MotionEvent){
this.label.text =
"加速度: \nx:"+e.accelerationIncludingGravity.x
+",\ny:"+e.accelerationIncludingGravity.y
+",\nz:"+e.accelerationIncludingGravity.z;
}
}