您当前的位置: 首页 >  ar

开发游戏的老王

暂无认证

  • 2浏览

    0关注

    803博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Godot Engine:Parent和Owner

开发游戏的老王 发布时间:2020-01-10 18:41:20 ,浏览量:2

Parent
  • 一个节点的Parent就是场景树上它的父级
Owner
  • 一个节点的Owner可以是除自身之外的任意有效的父节点(parent)或者祖父节点(grandparent)即节点树上的上级节点
  • 当存储一个节点时它所拥有的节点也都将会被保存
  • 如果不修改默认Owner的话,可以把它视为节点所在场景的顶部节点,如果该节点本身就是顶部节点那么它的Ownernull
实验一:静态场景结构中默认的Owner

在这里插入图片描述

每个节点的代码是相同的
extends Node

class_name TestNode

func _ready():
	var parent_name = "NULL"
	var owner_name = "NULL"
	if get_parent() != null:
		parent_name = get_parent().name
	if owner != null:
		owner_name = owner.name
	print(name + "'s parent is  and it's owner is " )
	
输出结果

node_3's parent is  and it's owner is 
node_2's parent is  and it's owner is 
node_1's parent is  and it's owner is 
node_0's parent is  and it's owner is 

实验二:动态创建的节点的Owner
extends Node

func _ready():
	var n = TestNode.new()
	n.name = ""
	add_child(n)

输出结果
's parent is  and it's owner is 

小结

  • 静态生成的节点的默认Owner是它的父节点,如果它没有父节点则Owner
  • 动态生成的节点的默认Ownernull
关注
打赏
1656935939
查看更多评论
立即登录/注册

微信扫码登录

0.0656s