Compare commits
2 commits
bbeb63cc62
...
b541ce8773
Author | SHA1 | Date | |
---|---|---|---|
Daniel Siepmann | b541ce8773 | ||
Daniel Siepmann | 9b42624c7d |
|
@ -3,18 +3,17 @@ extends Sprite2D
|
|||
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
|
||||
func _ready():
|
||||
var timer = get_node('Timer')
|
||||
timer.timeout.connect(_on_timer_timeout)
|
||||
|
||||
func _process(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
|
||||
func _on_timer_timeout():
|
||||
visible = not visible
|
||||
|
||||
func _on_button_pressed():
|
||||
set_process(not is_processing())
|
||||
|
|
20
scripting_first_script/node_2d.tscn
Normal file
20
scripting_first_script/node_2d.tscn
Normal file
|
@ -0,0 +1,20 @@
|
|||
[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)
|
||||
|
||||
[node name="Timer" type="Timer" parent="Sprite2D"]
|
||||
autostart = true
|
||||
|
||||
[connection signal="pressed" from="Button" to="Sprite2D" method="_on_button_pressed"]
|
Loading…
Reference in a new issue