diff --git a/scenes/button.tscn b/scenes/button.tscn new file mode 100644 index 0000000..7d29af3 --- /dev/null +++ b/scenes/button.tscn @@ -0,0 +1,19 @@ +[gd_scene load_steps=2 format=3 uid="uid://cn4bsud8kgyvp"] + +[ext_resource type="PackedScene" uid="uid://6ws803s4tnhy" path="res://scenes/icon.tscn" id="1_or1o1"] + +[node name="Node2D" type="Node2D"] + +[node name="Icon" parent="." instance=ExtResource("1_or1o1")] + +[node name="Timer" type="Timer" parent="Icon"] +autostart = true + +[node name="Button" type="Button" parent="."] +offset_left = 48.0 +offset_top = 33.0 +offset_right = 238.0 +offset_bottom = 108.0 +text = "Toggle motion" + +[connection signal="pressed" from="Button" to="Icon" method="_on_button_pressed"] diff --git a/scripts/icon.gd b/scripts/icon.gd index 91de13e..6c7bd70 100644 --- a/scripts/icon.gd +++ b/scripts/icon.gd @@ -3,17 +3,19 @@ extends Sprite2D var speed = 400 var angular_speed = PI +func _ready(): + var timer = get_node("Timer") + timer.timeout.connect(_on_timer_timeout) + func _process(delta: float) -> void: - var direction = 0 - if Input.is_action_pressed("ui_left"): - direction = -1 - if Input.is_action_pressed("ui_right"): - direction = 1 - - rotation += angular_speed * direction * delta - - var velocity = Vector2.ZERO - if Input.is_action_pressed("ui_up"): - velocity = Vector2.UP.rotated(rotation) * speed - + rotation += angular_speed * delta + var velocity = Vector2.UP.rotated(rotation) * speed position += velocity * delta + + +func _on_button_pressed() -> void: + set_process(not is_processing()) + + +func _on_timer_timeout(): + visible = not visible