//水杯脚本

cc.Class({
    extends: cc.Component,

    properties: {
        juiceLayout: cc.Node,   //显示果汁的节点
        juicePre: cc.Prefab,    //果汁预制
        spJuice: [cc.SpriteFrame], //果汁图片
        _juicePool: null,      
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {
        this._juicePool =new cc.NodePool("juicePool");
    },

    init: function(num,len){
        var juice =null;
        if (this._juicePool.size() > 0) {  //通过 size 接口判断水果对象池中是否有空闲的对象
            juice =this._juicePool.get();
        }else {    //如果没有空闲对象，也就是对象池中备用对象不够时，我们就用 cc.instantiate 重新创建
            //添加水果预制体
            juice =cc.instantiate(this.juicePre);   //取对应水果的预制体
        }
        juice.height =95/len;
        juice.getComponent(cc.Sprite).spriteFrame =this.spJuice[num];
        this.juiceLayout.addChild(juice);
    },

    //回收果汁预制节点
    onPutNode: function(){
        var length =this.juiceLayout.children.length;
        console.log("果汁节点",length);
        if(length){
            for(var i=length-1;i>=0;i--){
                // console.log("果汁回收HHHHHH",this.juiceLayout.children[i]);
                this._juicePool.put(this.juiceLayout.children[i]);    //放入水果对象池
            }
        }
    },


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