/**
 * 水果缩放脚本 
 */

cc.Class({
    extends: cc.Component,

    properties: {
        
    },


    onLoad () {
        // this.bigDistance = 70;
        // this.smallDistance = 120;

        // this.scaleType = 0;
    },
    
    onEnable(){
        // console.log("-----缩放")
        this.node.stopAllActions();

        this.startPosition = this.node.position;
        // let dir = this.startPosition.normalize();
        let dir =cc.pNormalize(this.startPosition);

        let actionBig = cc.moveBy(2, cc.p(dir.x * this.bigDistance, dir.y * this.bigDistance));
        let actionSmall = cc.moveBy(2, cc.p(dir.x * this.smallDistance * (-1), dir.y * this.smallDistance * (-1)));
        let delay1 = cc.delayTime(this.time1);
        let delay2 = cc.delayTime(this.time2);
        let doAction = cc.sequence(actionBig, delay1, actionSmall, delay2);
        let reverseAction = doAction.reverse();
        
        if(!this.scaleType) return;
        this.node.runAction(cc.repeatForever(cc.sequence(doAction, reverseAction)));
    },


    setData(bigDistance, smallDistance){
        this.bigDistance = bigDistance;
        this.smallDistance = smallDistance;
    },

    setIsScale(scaleType,time1,time2){
        this.scaleType = scaleType;
        this.time1 =time1;
        this.time2 =time2;
    }

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