Skip to content

Commit af4a557

Browse files
committed
add vibration
1 parent b820fed commit af4a557

File tree

3 files changed

+79
-7
lines changed

3 files changed

+79
-7
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ permissions:
88
contents: read
99

1010
env:
11-
GODOT_VERSION: 4.3-beta1
11+
GODOT_VERSION: 4.3-beta2
1212

1313
jobs:
1414
build:

Main.gd

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,20 @@ func _on_button_pressed():
1515
var instance = falling_object_scene.instantiate()
1616

1717
instance.position = Vector2(randf_range(0, get_viewport_rect().size.x), 0)
18-
18+
1919
add_child(instance)
2020

2121
# Called every frame. 'delta' is the elapsed time since the previous frame.
2222
func _process(_delta: float) -> void:
2323
pass
24+
25+
26+
func _on_button_2_pressed() -> void:
27+
print ("button pressed")
28+
var device := 0 # The joystick device index, change as needed
29+
var weak_magnitude := float($Weak.text) # Weak vibration strength (0 to 1)
30+
var strong_magnitude := float($Strong.text) # Strong vibration strength (0 to 1)
31+
var duration := float($Duration.text) # Duration in seconds
32+
33+
# Trigger joystick vibration
34+
Input.start_joy_vibration(device, weak_magnitude, strong_magnitude, duration)

node_2d.tscn

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[gd_scene load_steps=6 format=3 uid="uid://cuywatrvx6sg"]
1+
[gd_scene load_steps=7 format=3 uid="uid://cuywatrvx6sg"]
22

33
[ext_resource type="Script" path="res://Main.gd" id="1_kcb8k"]
44
[ext_resource type="PackedScene" uid="uid://ck8jprx4ew4io" path="res://FallingObject.tscn" id="2_6coth"]
@@ -11,6 +11,9 @@ default_font_size = 70
1111

1212
[sub_resource type="RectangleShape2D" id="RectangleShape2D_7dq5l"]
1313

14+
[sub_resource type="Theme" id="Theme_2l7dw"]
15+
default_font_size = 40
16+
1417
[node name="Node2D" type="Node2D"]
1518
script = ExtResource("1_kcb8k")
1619
falling_object_scene = ExtResource("2_6coth")
@@ -21,21 +24,32 @@ offset_bottom = 40.0
2124
scale = Vector2(4, 4)
2225

2326
[node name="SubViewport" type="SubViewport" parent="SubViewportContainer"]
27+
handle_input_locally = false
2428
canvas_item_default_texture_filter = 0
2529
size = Vector2i(40, 40)
30+
render_target_update_mode = 4
2631

2732
[node name="Label" type="Label" parent="SubViewportContainer"]
2833
layout_mode = 2
2934
theme = SubResource("Theme_p6gxr")
35+
text = "bananas: 0"
3036

3137
[node name="Button" type="Button" parent="."]
32-
offset_left = 244.0
33-
offset_top = 176.0
34-
offset_right = 771.0
35-
offset_bottom = 344.0
38+
offset_left = 82.0
39+
offset_top = 227.0
40+
offset_right = 609.0
41+
offset_bottom = 395.0
3642
theme = SubResource("Theme_ul4r8")
3743
text = "click me"
3844

45+
[node name="Button2" type="Button" parent="."]
46+
offset_left = 645.0
47+
offset_top = 227.0
48+
offset_right = 884.0
49+
offset_bottom = 395.0
50+
theme = SubResource("Theme_ul4r8")
51+
text = "vib"
52+
3953
[node name="StaticBody2D" type="StaticBody2D" parent="."]
4054

4155
[node name="CollisionShape2D2" type="CollisionShape2D" parent="StaticBody2D"]
@@ -52,3 +66,50 @@ shape = SubResource("RectangleShape2D_7dq5l")
5266
position = Vector2(857, 1807)
5367
scale = Vector2(100, 100)
5468
shape = SubResource("RectangleShape2D_7dq5l")
69+
70+
[node name="Weak" type="LineEdit" parent="."]
71+
offset_left = 255.0
72+
offset_top = 541.0
73+
offset_right = 425.0
74+
offset_bottom = 611.0
75+
theme = SubResource("Theme_2l7dw")
76+
text = "1.0"
77+
78+
[node name="Strong" type="LineEdit" parent="."]
79+
offset_left = 536.0
80+
offset_top = 543.0
81+
offset_right = 706.0
82+
offset_bottom = 613.0
83+
theme = SubResource("Theme_2l7dw")
84+
text = "1.0"
85+
86+
[node name="Duration" type="LineEdit" parent="."]
87+
offset_left = 806.0
88+
offset_top = 541.0
89+
offset_right = 976.0
90+
offset_bottom = 611.0
91+
theme = SubResource("Theme_2l7dw")
92+
text = "1.0"
93+
94+
[node name="Label" type="Label" parent="."]
95+
offset_left = 276.657
96+
offset_top = 477.172
97+
offset_right = 316.657
98+
offset_bottom = 500.172
99+
text = "weak"
100+
101+
[node name="Label2" type="Label" parent="."]
102+
offset_left = 561.0
103+
offset_top = 480.0
104+
offset_right = 602.0
105+
offset_bottom = 503.0
106+
text = "strong"
107+
108+
[node name="Label3" type="Label" parent="."]
109+
offset_left = 850.0
110+
offset_top = 481.0
111+
offset_right = 891.0
112+
offset_bottom = 504.0
113+
text = "duration"
114+
115+
[connection signal="pressed" from="Button2" to="." method="_on_button_2_pressed"]

0 commit comments

Comments
 (0)