Home > other >  Outside the cocos creator how in cc. Loader. LoadRes node of dynamic loading of prefab to operate?
Outside the cocos creator how in cc. Loader. LoadRes node of dynamic loading of prefab to operate?

Time:09-18

Cc. Class ({
Extends: cc.Com ponent,

Properties: {
Testnode: cc) Node,
},

OnLoad () {
Let action=cc. MoveTo (3, 700, 326);
var self=this;
Cc. Loader. LoadRes (" star1 ", function (err, prefab) {
Self. Testnode. AddChild (cc. Instantiate (prefab), 1, "ttnode");
Self. Testnode. GetChildByName (" ttnode "). RunAction (action);
});
//this. Testnode. GetChildByName (" ttnode "). RunAction (action);
},
});

This could be the node of the prefab,

Cc. Class ({
Extends: cc.Com ponent,

Properties: {
Testnode: cc) Node,
},

OnLoad () {
Let action=cc. MoveTo (3, 700, 326);
var self=this;
Cc. Loader. LoadRes (" star1 ", function (err, prefab) {
Self. Testnode. AddChild (cc. Instantiate (prefab), 1, "ttnode");
//self. Testnode. GetChildByName (" ttnode "). RunAction (action);
});
This. Testnode. GetChildByName (" ttnode "). RunAction (action);
},
});

After changing it, in cc. Loader. Can't loadRes outside of the prefab node, quote: [ERROR] : the object already destroyed,
How in the cc. Loader. LoadRes outside to dynamically add node of prefab to operate?
  • Related