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

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

7年前 (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

相关文章

AJAX无刷新彩票开奖程序制作

AJAX无刷新彩票开奖程序制作

 对彩票开奖进行显示的一个程序,采用ASP+ACCESS+AJAX+XML技术制作而成。Ajax调用数据,后台彩票开奖记录后前台无刷新显示;用户可自助生成开奖调用界面,可供其他网站对开奖数据...

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

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

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

测评EVO无人机

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

瑞丽市人民政府网站建设项目

瑞丽市人民政府网站建设项目

做这个项目的时候,刚好2013年春节的前的第2个星期,公司人手不够,临时让我出差去瑞丽跟客户沟通下这个网站的需求。本来我准备年前一个星期回家的,半路出来个这么个事。本来我就是过去谈谈需求,确认下需求让...

一个人的旅行·大理

一个人的旅行·大理

在结束上一份工作后,想着一个人出去走走吧。以前总是抱怨没时间出去,这下有时间了,但只有我一个人。大理 崇圣寺三塔洱海南诏风情岛充满商业气息的古城就不说了。 ...