Egret之龍骨卡槽 slot 換皮

2021-09-20 20:43:57 字數 2706 閱讀 8752

龍骨的是繫結在卡槽上的.並且是一對一的關係.所以可以通過對骨架的卡槽上繫結的的更換來實現另一種換皮的效果.

換皮的核心**:

//針對slot設定其新內容

private

setnewslot(slotname:string, texturename:string

)

我做了乙個工具:

module bg2tool

* @constructor

*/public

static get instance() : dragonboneanimationtools

return dragonboneanimationtools._instance;

}/**

* 防止類外例項化

*/private constructor(){}

/*** 設定骨骼卡槽的**

* @param $animation 骨骼動畫

* @param $slotname 卡槽名稱

* @param $texturename 紋理

*/public setnewslot( $animation : dragonbones.egretarmaturedisplay , $slotname:string, $texturename:string ) : void 紋理沒有配置!!!`);

}else 紋理沒有被載入!!!`);}}

}let slot:dragonbones.slot = $animation.armature.getslot($slotname);

let b:egret.bitmap = new egret.bitmap();

b.texture = res.getres( $texturename );

b.x = slot.display.x;

b.y = slot.display.y;

b.anchoroffsetx = b.width>>1;

b.anchoroffsety = b.height>>1;

slot.display = b;}}

}

現在準備測試

①: 準備龍骨資源

注意:球的資源繫結的卡槽名稱為 slot

看看初始骨骼動畫效果:

private $dragonbone : dragonbones.egretarmaturedisplay = null;
this.$dragonbone = bg2tool.dragonbonepoolresmanager.instance.getanimation4dragonbone(

"guajiselfbone_ske_json",

"guajiselfbone_tex_json",

"guajiselfbone_tex_png",

"guajianimation",1,1

);this._context.guajianimation.addchild( this.$dragonbone );

this.$dragonbone.x = 200;

this.$dragonbone.y = 400;

this.$dragonbone.animation.play("jumping",0);

結果:

換皮開始:

換成:

**:

this.$dragonbone = bg2tool.dragonbonepoolresmanager.instance.getanimation4dragonbone(

"guajiselfbone_ske_json",

"guajiselfbone_tex_json",

"guajiselfbone_tex_png",

"guajianimation",1,1

);this._context.guajianimation.addchild( this.$dragonbone );

this.$dragonbone.x = 200;

this.$dragonbone.y = 400;

this.$dragonbone.animation.play("jumping",0);

bg2tool.ressyncloadingmanager.instance.startloading( "1-1_99003_png" , this.changeskin.bind(this) );

private

changeskin($skin : string

) : void

}

結果 :

egret 變數 Egret全新RES模組詳解

近期egret發布了全新的4.0版本,此次版本中最大的特色就是釋放了全新的res資源管理模組。相信不少人在官網或者直播中已經對新的res資源管理模組有所了解。這篇文章就全新的res進行一次介紹。與此同時,在引擎新版本中,由於引入了typescript 2.1.4,所以在語法糖層面也增加不少特性,我後...

egret 效能測試

今天,看到一篇as3 addchild 顯示物件到舞台後執行,removerchild 的效能的消耗的問題。private function testremovechild void trace 建立物件計算用時 gettimer starttime,毫秒 starttime gettimer wh...

egret事件模型

定義了乙個事件派發類 class dispatcher extends egret.eventdispatcher 注意此處是public static,this指向dispatcher類,而不是它的例項 因此,instance必須定義為靜態成員才能獲取 public static get ins ...