- Godot Engine Game Development Projects
- Chris Bradfield
- 190字
- 2021-06-18 18:51:28
Script
Next, add a script to the Coin node. If you choose Empty in the Template setting, Godot will create an empty script without any comments or suggestions. The code for the coin's script is much shorter than the code for the player's:
extends Area2D
var screensize = Vector2()
func pickup():
queue_free()
The pickup() function is called by the player script and tells the coin what to do when it's been collected. queue_free() is Godot's node removal method. It safely removes the node from the tree and deletes it from memory along with all of its children. Later, you'll add a visual effect here, but for now the coin disappearing is good enough.
queue_free() doesn't delete the object immediately, but rather adds it to a queue to be deleted at the end of the current frame. This is safer than immediately deleting the node, because other code running in the game may still need the node to exist. By waiting until the end of the frame, Godot can be sure that all code that may access the node has completed and the node can be removed safely.
- Verilog HDL數字系統設計入門與應用實例
- Ansible Quick Start Guide
- 商戰數據挖掘:你需要了解的數據科學與分析思維
- Photoshop CS4經典380例
- CSS全程指南
- VB語言程序設計
- 網絡管理工具實用詳解
- Cloud Security Automation
- Visual C++項目開發案例精粹
- Mastering Ansible(Second Edition)
- 生成對抗網絡項目實戰
- Microsoft Dynamics CRM 2013 Marketing Automation
- Effective Business Intelligence with QuickSight
- 大數據:從基礎理論到最佳實踐
- Mastering Android Game Development with Unity