Cocos-克隆已有节点
跳到导航
跳到搜索
import { _decorator, Component, Node,instantiate, director } from 'cc'; const { ccclass, property } = _decorator; @ccclass("test") export class test extends Component { @property({type:Node}) private target: Node = null; @property({type:Node}) private parent_node: Node = null; start(){ let scene = director.getScene(); let node = instantiate(this.target); node.parent=this.parent_node; // 将克隆节点加到场景中 node.setPosition(100,100); //设置节点位置 } }