Cocos Creator 创建Prefab资源代码

 properties: {
	 PrefabName:cc.Prefab,
     PrefabX:0,
     PrefabY:0,
	 ...
	 }

函数

   showPrefab(PrefabName,x,y){
        var newItem = cc.instantiate(PrefabName);
        // 设置位置
        newItem.setPosition(x,y);
        // 将新增的节点添加到 Canvas 节点下面
        this.node.addChild(newItem);
        return newItem;
    },

调用

this.showPrefab(this.PrefabName,this.PrefabX,this.PrefabY);

你可能感兴趣的:(CocosCreator)