日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

可覆写的函数与创建节点

發布時間:2025/3/20 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 可覆写的函数与创建节点 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

以下所描述的這些可覆寫的函數,能夠應用于節點:

GDScript ? func _enter_tree():# When the node enters the _Scene Tree_, it becomes active# and this function is called. Children nodes have not entered# the active scene yet. In general, it's better to use _ready() # for most cases. pass func _ready(): # This function is called after _enter_tree, but it ensures # that all children nodes have also entered the _Scene Tree_, # and became active. pass func _exit_tree(): # When the node exits the _Scene Tree_, this function is called. # Children nodes have all exited the _Scene Tree_ at this point # and all became inactive. pass func _process(delta): # This function is called every frame. pass func _physics_process(delta): # This is called every physics frame. pass

如前所訴,用這些函數替代通知系統是更好的選擇。

創建節點

如果要用代碼方式創建一個節點, 只需調用?.new()?方法即可,這也適用于其他的基于類的數據類型。舉例說明:

GDScript ? var s func _ready():s = Sprite.new() # Create a new sprite! add_child(s) # Add it as a child of this node.

若要刪除一個節點,無論其是否在場景樹之內,?free()?方法一定會被調用:

GDScript ? func _someaction():s.free() # Immediately removes the node from the scene and frees it.

當一個節點被釋放時, 它也會釋放其所有子節點。因此, 手動刪除節點比看起來簡單得多。釋放基節點, 那么子樹中的其他所有東西都會隨之消失。

當我們要刪除一個當前處于“阻塞”狀態的節點時,就可能發生這種情況, 因為此時它正在發出信號或者在調用一個函數。這會導致游戲崩潰。使用調試器運行Godot通常能捕獲這種情況并向你發出警告。

刪除一個節點最安全的方法是使用?Node.queue_free()。這會在程序空閑時安全地擦除該節點。

GDScript ? func _someaction():s.queue_free() # Removes the node from the scene and frees it when it becomes safe to do so.

?

轉載于:https://www.cnblogs.com/empist/p/10200160.html

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的可覆写的函数与创建节点的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。