DisplayObject:显示对象基类,所有显示对象都继承此类
当前对象 addEventListener type:touchMove touchBegin touchEnd 等
基本属性:
x :x轴坐标值 y:y轴坐标值 width:宽度 height:高度
rotation:旋转角度 visible:是否可见 scaleX:横向缩放 scaleY:纵向缩放
anchorOffsetY:对象绝对锚点Y anchorOffsetX:对象绝对锚点X
skewX:横向斜切 skewY:纵向斜切
Shape
const shp : egret.Shape = new egret.Shape();
shp.graphics.beginFill(0xff0000,1);
shp.graphics.drawRect(0,0,50,50);
shp.graphics.endFill();
var shp1 = new egret.Shape();
shp1.graphics.lineStyle(2,0x00ff00);
shp1.graphics.beginFill(0xff0000,1);
shp1.graphics.drawEllipse(100,100,50,30);
shp1.graphics.endFill();
var shp2 = new egret.Shape();
shp2.x = 100;
shp2.y = 50;
shp2.graphics.lineStyle(2,0x00ff00);
shp2.graphics.beginFill(0xff00000,1);
shp2.graphics.drawCircle(0,0,50);
shp2.graphics.endFill();
var shp3 = new egret.Shape();
shp3.graphics.lineStyle(2,0x00ff00);
shp3.graphics.moveTo(100,100);
shp3.graphics.lineTo(200,200);
shp3.graphics.lineTo(200,100);
shp3.graphics.endFill();
var shp4 = new egret.Shape();
shp4.graphics.lineStyle(2,0xff00ff);
shp4.graphics.moveTo(100,100);
shp4.graphics.curveTo(150,150,200,50);
shp4.graphics.endFill();
var shp5 = new egret.Shape();
shp5.graphics.beginFill(0x1122cc);
shp5.graphics.drawArc(200,200,100,0,Math.PI,true);
shp5.graphics.endFill();
var shp6 = new egret.Shape();
shp6.graphics.lineStyle(2,0x561200);
shp6.graphics.drawArc(100,100,59,59,Math.PI/180*30,false);
shp6.graphics.endFill();
var shp7 = new egret.Shape();
shp7.graphics.beginFill(0x455444);
shp7.graphics.drawArc(300,300,100,200,Math.PI/180*60,false);
shp7.graphics.endFill();
const r: number = 50;
const shape: egret.Shape = new egret.Shape();
shape.graphics.lineStyle(3,0x000000);
shape.graphics.beginFill(0xff0000,1);
shape.graphics.moveTo(r, r); //绘制点移动(r, r)点
shape.graphics.lineTo(r * 2, r); //画线到弧的起始点
shape.graphics.drawArc(50, 50, 50, 0, 45* Math.PI / 180, true); //从起始点顺时针画弧到终点
shape.graphics.lineTo(r, r); //从终点画线到圆形。到此扇形的封闭区域形成
shape.graphics.endFill();
mask
var shp = new egret.Shape();
shp.graphics.beginFill(0x000000,1);
shp.graphics.drawRect(0,0,100,100);
shp.graphics.endFill();
this.sceneManger.mainstage.addChild(shp);
var shp1 = new egret.Shape();
shp1.graphics.beginFill(0xffffff,1);
shp1.graphics.drawCircle(50,50,20);
shp1.graphics.endFill();
this.sceneManger.mainstage.addChild(shp1);
shp.mask = shp1;
textfield
字体引用,需要提前加载资源
egret.registerFontMapping("myFont","resource/assets/font/myFont.ttf");
var lab = new egret.TextField();
lab.fontFamily = "myFont";
lab.text = "this is text ";
this.sceneManger.mainstage.addChild(lab);
var txtInput = new egret.TextField();
txtInput.type = egret.TextFieldType.INPUT;
txtInput.width = 100;
txtInput.height = 40;
txtInput.x = 50;
txtInput.y = 100;
txtInput.textColor = 0x000000;
//txtInput.text = "wqewqewq";
txtInput.setFocus();
this.sceneManger.mainstage.addChild(txtInput);
BitMap
图片显示
var img = new egret.Bitmap();
img.texture = RES.getRes("loading_json.loading_bar1_png");
img.width = 100;
img.height = 50;
img.fillMode = egret.BitmapFillMode.SCALE;
var rect = new egret.Rectangle(2,2,2,2);
img.scale9Grid = rect;
this.sceneManger.mainstage.addChild(img);
var texture = new egret.RenderTexture();
texture.drawToTexture( img);
img.texture = texture;
var textdata = RES.getRes("loading_json.loading_bar1_png");
textdata.saveToFile("image/png", "a/down.png", new egret.Rectangle(50, 30, 100, 100));
img.texture = textdata;
var img = new egret.Bitmap();
var texture = RES.getRes("egret_icon_png");
img.texture = texture;
//混合模式
//img.blendMode = egret.BlendMode.ERASE;
this.sceneManger.mainstage.addChild(img);
//滤镜
const colorMatrix = [
0.3, 0.6, 0, 0, 0,
0, 0.6, 0, 0, 0,
0.3, 0.6, 0, 0, 0,
0, 0, 0, 1, 0
];
const colorFlilter = new egret.ColorMatrixFilter(colorMatrix);
//img.filters = [colorFlilter];
const blurFliter = new egret.BlurFilter(1,1);
img.filters = [blurFliter];