diff --git a/scripting_first_script/Sprite2D.gd b/scripting_first_script/Sprite2D.gd index 7c0f258..b731cd8 100644 --- a/scripting_first_script/Sprite2D.gd +++ b/scripting_first_script/Sprite2D.gd @@ -4,17 +4,9 @@ var speed = 400 var angular_speed = PI func _process(delta): - 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 - + rotation += angular_speed * delta var velocity = Vector2.UP.rotated(rotation) * speed - if Input.is_action_pressed('ui_up'): - position += velocity * delta - - if Input.is_action_pressed('ui_down'): - position -= velocity * delta + position += velocity * delta +func _on_button_pressed(): + set_process(not is_processing()) diff --git a/scripting_first_script/node_2d.tscn b/scripting_first_script/node_2d.tscn new file mode 100644 index 0000000..7a46222 --- /dev/null +++ b/scripting_first_script/node_2d.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=2 format=3 uid="uid://c8sxdckrhknyo"] + +[ext_resource type="PackedScene" uid="uid://bxxuj5sw4p1oy" path="res://sprite_2d.tscn" id="1_1kdcd"] + +[node name="Node2D" type="Node2D"] + +[node name="Button" type="Button" parent="."] +offset_left = 53.0 +offset_top = 51.0 +offset_right = 172.0 +offset_bottom = 95.0 +text = "Toggle motion" + +[node name="Sprite2D" parent="." instance=ExtResource("1_1kdcd")] +position = Vector2(289, 187) + +[connection signal="pressed" from="Button" to="Sprite2D" method="_on_button_pressed"]