egret知(填)识(坑)点集

时间:2022-06-13
本文章向大家介绍egret知(填)识(坑)点集,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

1. egret.Label 富文本用法

...
public lbTest:eui.Label;
...

lbTest.textFlow=[
  {text:"hello",style:{size:12,textColor:oxffffff}},
   {text:"hello",style:{size:16,textColor:oxffff00}}
]

2. 骨骼动画

加载:

 let dragonebonesData = RES.getRes(<*.json>);
 let textureData = RES.getRes(<*_ske.json>); 
 let texture = RES.getRes(<*.png>);
 let factory:dragonBones.EgretFactory = new dragonBones.EgretFactory();
 factory.addDragonBonesData(dragonBones.DataParser.parseDragonBonesData(dragonebonesData));
 factory.addTextureAtlas(new dragonBones.EgretTextureAtlas(texture , textureData));

 var armature:dragonBones.FastArmature = factory.buildFastArmature(armatureName);
 armature.enableAnimationCache(30); 
...

替换控件,方法为dragonBones.Slot.setDisplay(dispaly:any),但是并不是每一次都能成功设置上,display也并不是一直有值,以下提供一种方式参考,并不一定对哈:

private testGroup:eui.Group;//参考点
...

armature.addEventListener(dragonBones.AnimationEvent.START, function(){
  egret.setTimeout(function(){
    let group = this.testGroup;
    let slot: dragonBones.Slot = armature.getSlot("<骨骼名称>");
    let cell = new <控件类>();
    cell.width =group.width;
    cell.height = group.height;
    cell.anchorOffsetX = group.width / 2;
    cell.anchorOffsetY = group.height / 2;
    slot.setDisplay(cell);    
 },this,200);
},this);  

3. 事件

按钮点击事件

private btnTest:eui.Button;
...
btnTest.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onTouch,this);
...
private onTouch(event){
  switch(event.target){
     case this.btnTest:{
        //TODO
      }
  }
}

控件加入和移除事件:

this.addEventListener(egret.Event.ADDED_TO_STAGE...
this.addEventListener(egret.Event.REMOVED_FROM_STAGE...

定时执行

...
let timer:egret.Timer = new egret.Timer(RETRY_INTERVALS[this._retries], 1);
timer.addEventListener(egret.TimerEvent.TIMER,this.text, this);
timer.start();
...
private test(event){
//TODO
}

4. 控件状态替换

class TestLayer eui.Component implements  eui.UIComponent{
...
this.skin.currentState = this.skin.states[0].name;
...
}

5.获取时间的方式

...
let date = Date.now()
...

6.http请求

http://edn.egret.com/cn/article/index/id/589