// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

const { ccclass, property } = cc._decorator;

@ccclass
export default class Message extends cc.Component {

    @property(cc.Label)
    txtMessage: cc.Label = null

    isShow: boolean = true;

    showMessage(message: string) {
        if (this.isShow) {
            this.isShow = false;
            cc.tween(this.node)
                .to(0.3, { position: cc.v3(0, 470), opacity: 255 })
                .delay(1)
                .call(() => {
                    cc.tween(this.node)
                        .to(0.3, { position: cc.v3(0, 310), opacity: 0 })
                        .call(()=> {
                            this.isShow = true;
                        })
                        .start();
                })
                .start();
            this.txtMessage.string = message;
        }
    }
}
