标签:obj logs isp tag 偏移量 code shape 构造 ble
class Main extends egret.DisplayObjectContainer {
/**
* 入口文件, 最先执行的构造方法
* 这会实例化一个和手机屏幕一样大的舞台
*/
public constructor() {
super();
this.once( egret.Event.ADDED_TO_STAGE, this.begin, this );
}
/**
* 入口文件加载成功后执行的方法
* 也是逻辑的开始, 通过触摸移动显示对象
*/
private begin(event:egret.Event) {
/**
* 定义两个偏移量
*/
var offsetX:number, offsetY:number;
/**
* 画一个红色的圆
*/
var circle: egret.Shape = new egret.Shape();
circle.graphics.beginFill(0xff0000);
circle.graphics.drawCircle(100,100,100);
circle.graphics.endFill();
this.addChild(circle);
/**
* 开启事件监听 并 绑定回调
* 实现简单的拖拽
*/
circle.touchEnabled = true;
circle.addEventListener(egret.TouchEvent.TOUCH_BEGIN, start, this);
circle.addEventListener(egret.TouchEvent.TOUCH_MOVE, move, this);
function start(ev:egret.TouchEvent):void {
circle.x = ev.stageX - 100;
circle.y = ev.stageY - 100;
}
function move(ev:egret.TouchEvent):void {
circle.x = ev.stageX - 100;
circle.y = ev.stageY - 100;
}
}
}
标签:obj logs isp tag 偏移量 code shape 构造 ble
原文地址:http://www.cnblogs.com/lovling/p/7569319.html