Godot:Signal
lastmod 2020-09-22created 2020-09-226 edits
An explanation of Signals in godot.
How to connect a signal in code
The syntax of the function is {소스_이름}.connect({시그널_이름}, {대상_이름}, {대상_함수_이름}). Here is the code for connecting the Timer:
public class TimerExample : Node2D
{
public override void _Ready()
{
GetNode("Timer").Connect("timeout", this, nameof(_on_Timer_timeout));
}
public void _on_Timer_timeout()
{
var sprite = GetNode<Sprite>("Sprite");
sprite.Visible = !sprite.Visible;
}
}
How to emit a signal
public class Main : Node
{
[Signal]
public delegate void MySignal(bool value, int other_value);
public override void _Ready()
{
EmitSignal(nameof(MySignal), true, 42);
}
}
See also
Favorite site
- Signals — Godot Engine (stable) documentation (Korean) - How to create and connect signals.