Node destroy and release dynamic loaded assets

Node destroy and release dynamic loaded assets
0
#1

i want release node what created on scripts.

[dynamic load asset(loadResDir) function] : it’s create new node and apply loaded sprite

var createdNodeList:cc.Node[] = [];

loadSpriteBulkLoading(){
            var self = this;
            cc.loader.loadResDir("sprites/explosion", cc.SpriteFrame, function (err, assets) {
            for(var i=0; i<assets.length; i++){
                nodes[i] = new cc.Node("bulkload_Sprite_" + i);
                var sp = nodes[i].addComponent(cc.Sprite);
                sp.spriteFrame = assets[i];
                nodes[i].parent = self.node;
                nodes[i].setPosition(-380 + i * 100, 220);

                self.createdNodeList[i] = nodes[i];
            }
        });
}

how can i release this nodes and assets?

            this.createdNodeList.forEach(function(c_node:cc.Node){
                // need it - 1?
                if(c_node.getComponent(cc.Sprite) != null){
                    cc.loader.release(c_node.getComponent(cc.Sprite));
                }
                // need it - 2?
                c_node.destroyAllChildren();
            });
            // just this okay? - 3?
            c_node.destroy();
            this.createdNodeList = [];

if when i do release the asset and node, need to release all sub(childrens) asset? (comment : need it? - 1,2)
or just node.destroy()? be okay? (comment : just this okay? - 3)

i found cc.removeSelf(). but it’s can’t be my code(it’s not self destroy)

when i just called `c_node.destroy()’, it have any problems?

#2

1 - no need
2 - no need
3 - no need

What you need inside forEach loop:

c_node.removeFromParent(true);
c_node.destroy();

1 Like
closed #3

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.