pixi-dragonbones-runtime
Version:
DragonBones Runtime for Pixi.js
3 lines (2 loc) • 2.6 kB
JavaScript
"use strict";require("../core/BaseObject.cjs");var e=require("../core/DragonBones.cjs"),r=require("pixi.js");class t extends r.Container{constructor(){super(),this.debugDraw=!1,this._debugDraw=!1,this._armature=null,this._debugDrawer=null,this._debugDrawerChildren=new Map}dbInit(e){this._armature=e}dbClear(){null!==this._debugDrawer&&(this._debugDrawerChildren.clear(),this._debugDrawer.destroy()),this._armature=null,this._debugDrawer=null,super.destroy()}dbUpdate(){const t=e.DragonBones.debugDraw||this.debugDraw;if(t||this._debugDraw)if(this._debugDraw=t,this._debugDraw){if(null===this._debugDrawer){this._debugDrawer=new r.Container;const e=new r.Graphics;this._debugDrawer.addChild(e)}this.addChild(this._debugDrawer);const e=this._debugDrawer.getChildAt(0);e.clear();const t=this._armature.getBones();for(let r=0,a=t.length;r<a;++r){const a=t[r],i=a.boneData.length,s=a.globalTransformMatrix.tx,n=a.globalTransformMatrix.ty,h=s+a.globalTransformMatrix.a*i,l=n+a.globalTransformMatrix.b*i;e.moveTo(s,n),e.lineTo(h,l),e.stroke({width:2,color:65535,alpha:.7}),e.circle(s,n,3),e.fill({color:65535,alpha:.7})}const a=this._armature.getSlots();for(let t=0,i=a.length;t<i;++t){const i=a[t],s=i.boundingBoxData;if(s){let t=this._debugDrawerChildren.get(i.name);switch(t||(t=new r.Graphics,this._debugDrawerChildren.set(i.name,t),this._debugDrawer.addChild(t)),t.clear(),s.type){case 0:t.rect(.5*-s.width,.5*-s.height,s.width,s.height);break;case 1:t.ellipse(.5*-s.width,.5*-s.height,s.width,s.height);break;case 2:const e=s.vertices;for(let r=0,a=e.length;r<a;r+=2){const a=e[r],i=e[r+1];0===r?t.moveTo(a,i):t.lineTo(a,i)}t.lineTo(e[0],e[1])}e.stroke({width:2,color:65535,alpha:.7}),i.updateTransformAndMatrix(),i.updateGlobalTransform();const a=i.global;t.updateTransform({x:a.x,y:a.y,scaleX:a.scaleX,scaleY:a.scaleY,rotation:a.rotation,skewX:a.skew,skewY:0,pivotX:i._pivotX,pivotY:i._pivotY})}else{const e=this._debugDrawerChildren.get(i.name);e&&(this._debugDrawerChildren.delete(i.name),this._debugDrawer.removeChild(e))}}}else null!==this._debugDrawer&&this._debugDrawer.parent===this&&this.removeChild(this._debugDrawer)}dispose(e=!0){null!==this._armature&&(this._armature.dispose(),this._armature=null)}destroy(){this.dispose()}dispatchDBEvent(e,r){this.emit(e,r)}hasDBEventListener(e){return this.listenerCount(e)>0}addDBEventListener(e,r,t){this.addListener(e,r,t)}removeDBEventListener(e,r,t){this.removeListener(e,r,t)}get armature(){return this._armature}get animation(){return this._armature.animation}}exports.PixiArmatureDisplay=t;
//# sourceMappingURL=PixiArmatureDisplay.cjs.map