"use strict";
cc._RF.push(module, 'e13a539J7VHXa42d0yvstL2', 'Curtain');
// scripts\Curtain.js

'use strict';

cc.Class({
    extends: cc.Component,

    properties: {
        padding: 0,
        spacing: 0,
        speed: 0,
        isMoveAble: true,
        nextIndex: 0,
        rows: 0,
        brickPrefab: cc.Prefab,
        maxBricksCount: 0
    },

    // use this for initialization
    onLoad: function onLoad() {
        this.brickPool = new cc.NodePool('Brick');
        for (var i = 0; i < this.maxBricksCount; i++) {
            var brickNode = cc.instantiate(this.brickPrefab);
            this.brickPool.put(brickNode);
        }
        this.addBrick(150);
        // setInterval(()=>{
        //     this.addBrick(100);
        // },10000)
    },

    addBrick: function addBrick(n) {
        for (var i = 0; i < n; i++) {
            var brickNode = null;
            if (this.brickPool.size() > 0) {
                brickNode = this.brickPool.get();
                cc.log('get');
            } else {
                cc.log('new');
                brickNode = cc.instantiate(this.brickPrefab);
            }
            brickNode.parent = this.node;
            brickNode.x = this.padding + this.nextIndex % this.rows * (brickNode.width + this.spacing) + brickNode.width / 2;
            brickNode.y = this.padding + Math.floor(this.nextIndex / this.rows) * (brickNode.height + this.spacing) + brickNode.height / 2;
            this.nextIndex++;
        }
    },
    removeBrick: function removeBrick(brickNode) {
        // brickNode.removeFromParent();
        this.brickPool.put(brickNode);
    }
});

cc._RF.pop();