- 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.
- Java編程全能詞典
- Learning Microsoft Azure Storage
- Excel 2007函數與公式自學寶典
- Getting Started with MariaDB
- Hands-On Data Science with SQL Server 2017
- 數據庫原理與應用技術學習指導
- 數據挖掘實用案例分析
- 機器自動化控制器原理與應用
- Expert AWS Development
- Windows程序設計與架構
- 永磁同步電動機變頻調速系統及其控制(第2版)
- 基于ARM 32位高速嵌入式微控制器
- 數據庫系統原理及應用教程(第5版)
- Photoshop CS5圖像處理入門、進階與提高
- AVR單片機工程師是怎樣煉成的