
cc.Class({
    extends: cc.Component,

    properties: {
       
    },

    start () {
        var self = this;
        self.node.on(cc.Node.EventType.TOUCH_START, self.touchStartEvent, self); 
        self.node.on(cc.Node.EventType.TOUCH_END, self.touchEndEvent, self); 
        self.node.on(cc.Node.EventType.TOUCH_MOVE, self.touchMoveEvent, self); 
        self.node.on(cc.Node.EventType.TOUCH_CANCEL, self.touchCancelEvent, self);  
        this.GameMode = this.node.parent.parent.getComponent('GameMode')
        this.timerNum = 0   //长按移动按钮计时
        this.isMove = 0 //开始运动标志
    },
    touchStartEvent(){
        this.node.children[0].scale = 0.9
        this.isMove = 1
    },
    touchEndEvent(){
        this.node.children[0].scale = 1
        this.isMove = 0        
    },
    touchMoveEvent(){
        this.node.children[0].scale = 0.9        
    },
    touchCancelEvent(){
        this.node.children[0].scale = 1
        this.isMove = 0        
    },
    update (dt) {
        if(this.GameMode.isPause)
        return
        if(this.isMove){
            if(this.GameMode.EnergyBlue.width<=0)
            return
            if(!this.GameMode.isUsingTool)
            this.GameMode.EnergyBlue.width--
            if(this.GameMode.EnergyBlue.width<0)
            this.GameMode.EnergyBlue.width=0
            var distanceNum = this.node.name == 'LeftButton' ? -4 : 4
            if(Math.abs(this.GameMode.Player.x+distanceNum)>300)
            distanceNum = 0
            this.GameMode.Player.x += distanceNum
            if(this.GameMode.playerLeft){
                this.GameMode.playerLeft.x += distanceNum
                this.GameMode.playerRight.x += distanceNum
            }
            
        }
    },
});
