doc
parent
1e083ddca5
commit
4026a6580a
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/owner01.png-3d92fe1a6d5d29fa03c5310ffc95f2cf.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://doc/demo03_lifecycle/image/owner01.png"
|
||||
dest_files=[ "res://.import/owner01.png-3d92fe1a6d5d29fa03c5310ffc95f2cf.stex" ]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=0
|
||||
flags/filter=true
|
||||
flags/mipmaps=false
|
||||
flags/anisotropic=false
|
||||
flags/srgb=2
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
|
@ -104,3 +104,40 @@ var subNode4 = get_tree().root.find_node("SubNode2", true, false)
|
|||
![Image text](image/physics.png)
|
||||
![Image text](image/physics-1.png)
|
||||
|
||||
# 6. Parent和Owner
|
||||
|
||||
- Parent
|
||||
- 一个节点的Parent就是场景树上它的父级
|
||||
|
||||
- Owner
|
||||
- 如果不修改默认Owner的话,可以把它视为节点所在场景的顶部节点,如果该节点本身就是顶部节点那么它的Owner为null
|
||||
|
||||
|
||||
- 静态场景结构中默认的Owner
|
||||
|
||||
![Image text](image/owner01.png)
|
||||
|
||||
```
|
||||
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 <" + parent_name + "> and it's owner is <" + owner_name + ">" )
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
node_3's parent is <node_2> and it's owner is <node_0>
|
||||
node_2's parent is <node_1> and it's owner is <node_0>
|
||||
node_1's parent is <node_0> and it's owner is <node_0>
|
||||
node_0's parent is <root> and it's owner is <NULL>
|
||||
```
|
||||
|
||||
- 动态创建的节点的Owner是null
|
|
@ -53,8 +53,28 @@ disconnect("mySignal", 1, 2)
|
|||
# 3. 异步回调yield
|
||||
|
||||
- yield, to produce a result, answer, or piece of information,立即结束当前函数调用,无需等待
|
||||
|
||||
```
|
||||
其本质,就是能让一个函数在执行过程中暂停(挂起),然后在接收到恢复指令以后继续执行的机制。
|
||||
```
|
||||
|
||||
- yield(obj, signal),函数立即返回,并且保存当前执行的位置和状态
|
||||
|
||||
```
|
||||
GDScriptFunctionState yield( Object object=null, String signal="" )
|
||||
```
|
||||
|
||||
- yield返回GDScriptFunctionState类型对象,类似于Java的CompleteFuture
|
||||
|
||||
```
|
||||
GDScriptFunctionState 是记录一个协程状态的对象,实际上它就代表(引用)着该协程。
|
||||
```
|
||||
|
||||
- resume恢复GDScriptFunctionState保存的调用函数状态
|
||||
|
||||
![Image text](image/yield.JPG)
|
||||
![Image text](image/yield.JPG)
|
||||
|
||||
- yield的三种用法
|
||||
1. yield()和resmue()组合,yield()来挂起,用resmue()来恢复
|
||||
2. yield(节点对象N,信号S)的形式,把这个协程(即 GDScriptFunctionState)注册为 节点N上信号S的接收者,当 节点N发出信号S以后,函数会恢复执行。
|
||||
3. yield(协程对象C,"completed")的形式,协程失效(即GDScriptFunctionState的is_valid为false)以后,它会释放一个"completed"信号,用这个信号恢复上一层协程。
|
||||
|
|
Loading…
Reference in New Issue