作成者オブジェクトプールのフライウェイトモードの使用

const {ccclass、property} = cc._decorator;

YBConst、{PopupLayerZorder}を '../core/constant/YBConst'からインポートします。

YBLogを '../core/utils/YBLog'からインポートします。

/ **

 *矢尻のオブジェクトプール。

 * /

@ccclass

デフォルトクラスのエクスポートArrowTailPool extends cc.Component {

    //ライフサイクルコールバック:

    enemyPool:cc.NodePool;

 

    onLoad(){

        // YBLog.log( "NodeBgPool"、 "25 25 25 object pool");

        this.enemyPool = new cc.NodePool();

    };

 

    public getparticleTail(callback):any {

        if(this.enemyPool.size()> 0){

            let Node = this.enemyPool.get();

            callback(newNode);

        } そうしないと {

            //YBLog.log("NodeBgPool "、" New Object ");

            //空きオブジェクトがない場合は、cc.instantiateを使用して再作成します

            cc.resources.load( "dynamicRes / prefab / tail"、cc.Prefab、function(err、prefab){

                もし(err){

                    cc.error(err);

                    nullを返します。

                }

                let newNode = cc.instantiate(prefab);

                this.enemyPool.put(newNode); // putインターフェースを介してオブジェクトプールに配置

                callback(this.enemyPool.get());

            } .bind(this));

        }

    }

    //リサイクル 

    public huishou(newNode:any){

        if(newNode){

            this.enemyPool.put(newNode); // putインターフェースを介してオブジェクトプールに配置

          // YBLog.log( "ArrowTailPool"、 "リサイクル後:"、this.enemyPool.size());

        }

    }

    //リサイクル 

    public clearAll(){

        this.enemyPool.clear(); // putインターフェースを介してオブジェクトプールに配置

        // YBLog.log( "NodeBgPool"、 "クリーニング後:"、this.enemyPool.size());

    }

    start(){

      // YBLog.log( "NodeBgPool"、 "Initialize");

    }

    //(dt)を更新します{}

}

おすすめ

転載: blog.csdn.net/ting100/article/details/108754995