// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        startPosition: cc.Vec2,
        voice: cc.AudioClip,
        voice2: cc.AudioClip,
    },
    // LIFE-CYCLE CALLBACKS:
    onLoad() {
        this.ske = this.node.getChildByName("ske");
        this.ske.x = this.startPosition.x;
        this.ske.y = this.startPosition.y;
        // //动画播放测试
        // let db = this.ske.getComponent(dragonBones.ArmatureDisplay)
        // db.playAnimation('normal');
        // console.log(db.timeScale);
        // setTimeout(() => {
        //     db.timeScale = 0.0001;
        //     console.log(db.timeScale);
        // }, 1000);
        // setTimeout(() => {
        //     db.timeScale = 1;
        //     console.log(db.timeScale);
        // }, 2000);
    },
    play() {
        return new Promise((resolve, reject) => {
            this.node.active = true;
            cc.audioEngine.playEffect(this.voice, false);
            setTimeout(() => {
                cc.audioEngine.playEffect(this.voice2, false);
            }, 500);
            let db = this.ske.getComponent(dragonBones.ArmatureDisplay)
            db.playAnimation('normal', 1);
            db.addEventListener("loopComplete", () => {
                // resolve('');
            })
            setTimeout(() => {
                resolve('');
            }, 2000);
        });

    }
    // update (dt) {},
});
