// 龙骨demo
module game {
export class DragonDemo extends egret.DisplayObjectContainer {
private objNum: number = 0;
private boo: boolean = false;
private arr: Array<dragonBones.EgretArmatureDisplay> = [];
private head;
private index:number = 0;
public constructor(num: number) {
super();
this.objNum = num;
this.once(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
}
private onAddToStage(evt: egret.Event) {
this.createDragonBones();
}
private createDragonBones() {
let ske = RES.getRes("robot3_ske_json");
let texJson = RES.getRes("robot3_tex_json");
let tex = RES.getRes("robot3_tex_png");
var factory: dragonBones.EgretFactory = dragonBones.EgretFactory.factory;
factory.parseDragonBonesData(ske);
factory.parseTextureAtlasData(texJson, tex);
this.arr = [];
for (let i = 0; i < this.objNum; i++) {
this.arr[i] = factory.buildArmatureDisplay("Armature");
this.addChild(this.arr[i]);
this.arr[i].y = 350;
if (i) {
this.arr[i].x = this.arr[i - 1].x + 0.5;
} else {
this.arr[i].x = 250;
}
this.arr[i].animation.play("await");
}
let btn = new eui.Button;
this.addChild(btn);
btn.x = 100;
btn.y = 100;
btn.label = `切换动作`;
btn.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.click, this);
}
private click() {
/*换装主要逻辑*/
this.index ++;
this.index %= 4;
console.log("this.index = " + this.index);
this.arr[0].armature.getSlot("右武器").displayIndex = this.index;
/***************/
/*切换动画*/
this.boo = !this.boo;
this.head = this.arr[0].armature.getBone("右武器");
if (this.boo) {
this.arr[0].animation.play("ATK");
}
else {
this.arr[0].animation.play("await");
}
/*************/
}
}
}