/**
* Author:W
* 节点的创建、克隆、销毁
*/
cc.Class({
extends: cc.Component,
properties: {
sprite:{
default:null,
type:cc.SpriteFrame,
},
prefab:{
default:null,
type:cc.Prefab,
}
},
start () {
this.createNode();
this.cloneNode();
setTimeout(function(){
this.spriteObj.destroy();
cc.log("销毁节点");
}.bind(this),3000);
},
//创建节点:通过new cc.Node()创建节点
createNode:function(){
var node = new cc.Node('Sprite');
var sp = node.addComponent(cc.Sprite);
sp.spriteFrame = this.sprite;
node.parent = this.node;
this.spriteObj = node;
cc.log("创建节点");
},
//克隆节点:cc.instantiate()
cloneNode:function(){
var node = cc.instantiate(this.prefab);
node.parent = this.node;
node.setPosition(10,10);
cc.log("克隆节点");
}
});
节点的创建克隆以及销毁
最新推荐文章于 2024-04-24 09:42:28 发布