cc.Class({
extends: cc.Component,
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);
},
});
這樣是可以對產生的prefab的node進行操作的。
cc.Class({
extends: cc.Component,
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);
},
});
改成這樣后,在cc.loader.loadRes外就不能對產生的prefab的node進行操作,報:[ERROR]: object already destroyed。
如何在cc.loader.loadRes外面對動態添加的prefab 的node進行對操作?
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/45728.html
標籤:Cocos2d-x
