Cocos-克隆已有节点

来自泡泡学习笔记
BrainBs讨论 | 贡献2023年6月28日 (三) 16:35的版本 (创建页面,内容为“ 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; // 将克…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳到导航 跳到搜索
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);     //设置节点位置
    }
}