赞
踩
/** * 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("克隆节点"); } });
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。