当前位置:首页 > 未命名 > 正文内容

Egret教程 egret.Shape 显示对象绘制图形

8年前 (2018-05-22)未命名
private drawGrid() { // 绘制
    //指定填充色开始填充
    this.graphics.beginFill(0x000ff);
    //绘制矩形,指定位置和宽高
    this.graphics.drawRect(0, 0, 50, 50);
    //结束填充
    this.graphics.endFill();
    this.graphics.beginFill(0x000ff);
    this.graphics.drawRect(50, 50, 50, 50);
    this.graphics.endFill();
    this.graphics.beginFill(0xff0000);
    this.graphics.drawRect(50, 0, 50, 50);
    this.graphics.endFill();
    this.graphics.beginFill(0xff0000);
    this.graphics.drawRect(0, 50, 50, 50);
    this.graphics.endFill();
}
private onAddToStage(event: egret.Event) {
		var shp: egret.Shape = new egret.Shape();
		shp.graphics.beginFill(0x00ff00);
		shp.graphics.drawRect(0, 0, 100, 100);
		shp.graphics.endFill();

		//改变矩形的位置(左上角顶点)
		shp.x = 100;
		shp.y = 100;

		//修改锚点的位置
		shp.anchorOffsetX = 50;
		shp.anchorOffsetY = 50;
		this.addChild(shp);
}

//通过触摸移动显示对象
	private moveObjectByTouch(): void {
		var draggedObject: egret.Shape;
		var offsetX: number;
		var offsetY: number;

		var circle: egret.Shape = new egret.Shape();
		circle.graphics.beginFill(0xff0000);
		circle.graphics.drawCircle(25, 25, 25);
		circle.graphics.endFill();
		this.addChild(circle);

		circle.touchEnabled = true;
		// circle.addEventListener(egret.TouchEvent.TOUCH_BEGIN, startMove, this);
		circle.addEventListener(egret.TouchEvent.TOUCH_BEGIN, (e: egret.TouchEvent) => {
			//记录手指按到的对象
			draggedObject = e.currentTarget;
			offsetX = e.stageX - circle.x;
			offsetY = e.stageY - circle.y;
			//将触摸的对象置于容器顶层
			this.addChild(draggedObject);
			this.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, onMove, this);
		}, this);
		circle.addEventListener(egret.TouchEvent.TOUCH_END, stopMove, this);

		function stopMove(e: egret.TouchEvent): void {
			console.log("stopMove");
			this.stage.removeEventListener(egret.TouchEvent.TOUCH_MOVE, onMove, this);
		}
		function onMove(e: egret.TouchEvent): void {
			draggedObject.x = e.stageX - offsetX;
			draggedObject.y = e.stageY - offsetY;
		}
	}


扫描二维码推送至手机访问。

版权声明:本文由小祥子的博客发布,如需转载请注明出处。

本文地址:http://www.xiaoxiangzi.com/post/72.html

相关文章

测评EVO无人机

在本地的无人机群里了解到EVO无人机,于是在淘宝里买了一台回来玩,但收到货后发现跟想象的不一样。关于APP与遥控器首先在APPStore中没有找到这款无人机的APP,国内各大安卓市场也没有找到,最后在...

发现个大BUG,结果...我错了

   首先,有个好消息就是我之前考的《网络通信安全管理员》通过了,有了它,公司的经营性ICP备案就有着落了。鼓掌,啪啪啪~另外,由于我打算学习IOS,所以准备新建一个IOS栏目,作为我的学习...

一个人的旅行·丽江

一个人的旅行·丽江

 大理玩了三四天,下一站,丽江。茶马古道拉市海玉龙雪山玉龙雪山下的蓝月谷泸沽湖去泸沽湖的时候,可谓是一波三折。遇到坑爹的旅行社,我的费用比同车人最低的多一倍,比除我之外最高的也多100,最终...

一键生成网站程序生成了个防水材料网

用一键生成网站的程序做了个防水材料网站,也顺便在这里吸引下蜘蛛 www.fangshui123.com 。弄了定时发布,以及伪静态,一键只是将相关的关键词入库,再有ASP文件来采集相应关键词...

OC时间戳转时间方法系列

// 时间戳转时间 + (NSString *)timeStampConv:(NSString *)timestamp; // 秒转换成00:00...

VB做的一个自动获取最新任务的小程序

VB做的一个自动获取最新任务的小程序

以前就爱使用Zblog,如今一看,居然有PHP的版本,果断下载了一个来使用。平时没事的时候,可以写写博文,或者记录一些好用的代码。最近学了PHP与VB,并且都开发了点小程序出来,当然,必须得实用或者能...