Skip to content

Instantly share code, notes, and snippets.

@brettchalupa
Created April 3, 2023 13:37
Show Gist options
  • Save brettchalupa/2af7ed29ee3d29340860eaa57f9c2c69 to your computer and use it in GitHub Desktop.
Save brettchalupa/2af7ed29ee3d29340860eaa57f9c2c69 to your computer and use it in GitHub Desktop.
Signals in Godot 4
extends Sprite2D
var rotating = true
signal rotating_toggled(is_rotating:bool)
func _ready() -> void:
rotating_toggled.emit(rotating)
func _process(delta: float) -> void:
if rotating:
rotate(delta)
func _input(event: InputEvent) -> void:
if event.is_action_pressed("ui_accept"):
rotating = !rotating
rotating_toggled.emit(rotating)
extends Node2D
func _process(delta: float) -> void:
pass
func _on_icon_rotating_toggled(is_rotating) -> void:
var text = ""
if is_rotating:
text = "Rotating: active"
else:
text = "Rotating: paused"
$RotatingStatus.text = text
extends Node2D
var rotate_icon = true
func _process(delta: float) -> void:
if rotate_icon:
$Icon.rotate(delta)
func _on_timer_timeout() -> void:
rotate_icon = !rotate_icon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment