Events in Godot🎉
• Events connect nodes.
• They are used for communication.
• Events make games interactive.
• They simplify node interactions.
2.
What are Events?⚡
• Events are triggered by input or system.
• They are handled by signals.
• They simplify code structure.
• They improve readability.
3.
Types of Events
•Input events capture user actions.
• Built-in signals trigger automatically.
• Custom signals are user-defined.
• They cover most interactions.
4.
Node Tree Flow🌳
• Events propagate through the scene tree.
• They can be caught at multiple levels.
• Handled by _input or _unhandled_input.
• UI nodes use _gui_input.
5.
InputEvent Example
• Checkfor key press.
• Check for mouse click.
• Check for touch input.
• Handle actions in _input.
6.
Custom Signals
• Definea signal in script.
• Emit with emit_signal().
• Connect with connect() method.
• They decouple node logic.
7.
Event Bus Pattern
•Use singleton for global events.
• Centralizes communication.
• Avoids tight coupling.
• Keeps nodes organized.
8.
One-Time Events
• Useflags to avoid repetition.
• Good for cutscenes.
• Ensures unique triggers.
• Simplifies gameplay flow.
9.
Input + SignalExample
• Player jumps on key press.
• Signal triggers animation.
• Animation plays once.
• Node stays decoupled.
10.
UI Events
• Use_gui_input for buttons.
• Detect clicks on UI.
• Prevent event propagation.
• Useful for menus.