start :function(){
var scene = cc.director.getScene();
this.p_node = cc.instantiate(this.node);
this.p_node.position = cc.v2(1,200);
this.p_node.parent = scene;
this.scheduleOnce(function() {
cc.log('**************************************');
this.p_node.destroy();
}, 2);
}
这段代码,cc.log会一直输出,但是官方文档中的说法应该是只会执行一次啊,
而且在执行的时候,我创建出来的一个图片没有被销毁,log则是一直输出 Object already destroyed ,
如果改成setTimeOut则会直接报出 destroy of null
start :function(){
var scene = cc.director.getScene();
this.p_node = cc.instantiate(this.node);
this.p_node.position = cc.v2(1,200);
this.p_node.parent = scene;
setTimeout(function(){
cc.log('**************************************');
this.p_node.destroy();
}.bind(this),2000);
}
而且,注释掉这段代码后,退出游戏时,'Destroy WebGLBuffer OR Destroy WebGLTesture by GC' 最多不会超过十个,加上之后,游戏运行一段时间退出就会到达几百个,是哪个方面出错了吗,求大佬解答一下 - - 场景中只有一个Canvas 和一个Sprite 脚本是挂在Sprite上的
已找到,
1 : setTimeout如果内部代码出错就会一直执行,
2 : 拷贝节点赋值给公共参数会无法des,或者说log里面打印了des,但实际游戏中还是会有这个(不知道为什么,官网论坛没人回复),修改代码为
start: function () {
this.p_node = new cc.Node('Sprite');
var sp = this.p_node.addComponent(cc.Sprite);
sp.spriteFrame = this.getComponent(cc.Sprite).spriteFrame;
this.p_node.parent = this.node;
this.p_node.position = cc.v2(0,100);
setTimeout(function(){
p_node.destroy();
}.bind(this), 2000);
},
```运行正常
MDZZ , 上面代码一直生成的节点出错了,也就是说我一直在生成和开启计时,对不起对不起 ,我的错
this.p_node = cc.instantiate(this.node);
你每次instantiate都是自己节点。每个节点instantiate后又重新调用start()函数。出现了死循环!