summaryrefslogtreecommitdiff
path: root/hello_signals/demo/Main.gd
diff options
context:
space:
mode:
authorfhuya <fhuya@google.com>2020-03-27 01:35:23 -0700
committerfhuya <fhuya@google.com>2020-03-27 01:35:23 -0700
commit8a50b716f5d335d0c060eb096032fc2d214dc635 (patch)
tree720c5f933732a949e0c2368a4cb0ee62354d9c28 /hello_signals/demo/Main.gd
parent6837796a9d7acd3a5ea7ef241a23fd393c3a6609 (diff)
downloadgodot-android-samples-8a50b716f5d335d0c060eb096032fc2d214dc635.tar.gz
godot-android-samples-8a50b716f5d335d0c060eb096032fc2d214dc635.tar.bz2
godot-android-samples-8a50b716f5d335d0c060eb096032fc2d214dc635.zip
Add `HelloSignals` sample project to show how to register and emit signals with a Godot Android plugin
Diffstat (limited to 'hello_signals/demo/Main.gd')
-rw-r--r--hello_signals/demo/Main.gd29
1 files changed, 29 insertions, 0 deletions
diff --git a/hello_signals/demo/Main.gd b/hello_signals/demo/Main.gd
new file mode 100644
index 0000000..22e5255
--- /dev/null
+++ b/hello_signals/demo/Main.gd
@@ -0,0 +1,29 @@
+extends Node2D
+
+var timerCount = 0
+var timerRunning = false
+var helloSignals
+
+func _ready():
+ if Engine.has_singleton("HelloSignals"):
+ helloSignals = Engine.get_singleton("HelloSignals")
+ helloSignals.connect("TikTok", self, "_on_tiktok")
+
+ $Button.connect("pressed", self, "_on_Button_pressed")
+ else:
+ print("Couldn't find HelloSignals singleton")
+
+
+func _on_tiktok():
+ print("TikTok signal received")
+ timerCount = timerCount + 1
+ $Label.text = str(timerCount)
+
+func _on_Button_pressed():
+ print("on button pressed from GDScript")
+ helloSignals.onButtonPressed()
+ timerRunning = !timerRunning
+ if (timerRunning):
+ $Button.text = "Stop Timer"
+ else:
+ $Button.text = "Start Timer"