瀏覽代碼

update joystick demo with joy_connection_changed handling

hondres 9 年之前
父節點
當前提交
31d441f409
共有 2 個文件被更改,包括 9 次插入0 次删除
  1. 9 0
      demos/misc/joysticks/joysticks.gd
  2. 二進制
      demos/misc/joysticks/joysticks.scn

+ 9 - 0
demos/misc/joysticks/joysticks.gd

@@ -51,3 +51,12 @@ func _fixed_process(delta):
 
 func _ready():
 	set_fixed_process(true)
+	Input.connect("joy_connection_changed", self, "_on_joy_connection_changed")
+
+#Called whenever a joystick has been connected or disconnected.
+func _on_joy_connection_changed(device_id, connected):
+	if device_id == cur_joy:
+		if connected:
+			get_node("joy_name").set_text(Input.get_joy_name(device_id))
+		else:
+			get_node("joy_name").set_text("")

二進制
demos/misc/joysticks/joysticks.scn