BackDoor.ts 1.73 KB
Newer Older
liujiangnan's avatar
liujiangnan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.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

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    // @property(cc.Label)
    // label: cc.Label = null;

    // @property
    // text: string = 'hello';
    @property
    need: number = 5;

    touchCounter = 0;
    countTimer = null;
    hat = null;
    // isDebug = false;

    // touchTimeline = [];

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}
    isDebug() {
        return this.hat && this.hat.active;
    }
    start () {
        console.log(111)
        this.hat = this.node.getChildByName('hat');
        if (!this.hat) {
            return;
        }
        this.node.on(cc.Node.EventType.TOUCH_START, () => {
            // console.log(Date.now());
            // this.touchTimeline.push(Date.now());
            this.touchCounter++;
            if (!this.countTimer) {
                this.countTimer = setTimeout(() =>{
                    this.touchCounter = 0;
                    clearTimeout(this.countTimer);
                    this.countTimer = null;
                }, 2000);
            }
            if (this.touchCounter == this.need) {
                clearTimeout(this.countTimer);
                this.countTimer = null;
                if (this.hat.active) {
                    this.hat.active = false
                } else {
                    this.hat.active = true
                }
                
            }
        });
    }

    // update (dt) {}
}