Step by step - Using signals

This commit is contained in:
Laegnur 2024-09-11 19:03:50 +02:00
parent 6240748512
commit 9753d64712
Signed by: laegnur
GPG key ID: F8FE83A0B2D932A3
12 changed files with 46 additions and 25 deletions

View file

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

View file

@ -3,15 +3,15 @@
importer="texture" importer="texture"
type="CompressedTexture2D" type="CompressedTexture2D"
uid="uid://dkq1swbmmxmbq" uid="uid://dkq1swbmmxmbq"
path="res://.godot/imported/Bouncy Platform Long.png-9b2628c180785c5ec622adb5c4ee7b17.ctex" path="res://.godot/imported/Bouncy Platform Long.png-9922f702bfe5975e9b12c011e324e6e1.ctex"
metadata={ metadata={
"vram_texture": false "vram_texture": false
} }
[deps] [deps]
source_file="res://assets/Bouncy Platform Long.png" source_file="res://assets/img/Bouncy Platform Long.png"
dest_files=["res://.godot/imported/Bouncy Platform Long.png-9b2628c180785c5ec622adb5c4ee7b17.ctex"] dest_files=["res://.godot/imported/Bouncy Platform Long.png-9922f702bfe5975e9b12c011e324e6e1.ctex"]
[params] [params]

View file

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

View file

@ -3,15 +3,15 @@
importer="texture" importer="texture"
type="CompressedTexture2D" type="CompressedTexture2D"
uid="uid://blqm0e7gm75u3" uid="uid://blqm0e7gm75u3"
path="res://.godot/imported/Bouncy Platform Medium.png-7896338a5f44da1e83084c154a3c4a9e.ctex" path="res://.godot/imported/Bouncy Platform Medium.png-ff51edd1d52c01a38d58a533c35f8a59.ctex"
metadata={ metadata={
"vram_texture": false "vram_texture": false
} }
[deps] [deps]
source_file="res://assets/Bouncy Platform Medium.png" source_file="res://assets/img/Bouncy Platform Medium.png"
dest_files=["res://.godot/imported/Bouncy Platform Medium.png-7896338a5f44da1e83084c154a3c4a9e.ctex"] dest_files=["res://.godot/imported/Bouncy Platform Medium.png-ff51edd1d52c01a38d58a533c35f8a59.ctex"]
[params] [params]

View file

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

View file

@ -3,15 +3,15 @@
importer="texture" importer="texture"
type="CompressedTexture2D" type="CompressedTexture2D"
uid="uid://dv6rx85s1gy3i" uid="uid://dv6rx85s1gy3i"
path="res://.godot/imported/ballBlue_10.png-a6ac20f1eeff46860499a0f8c7bba4ff.ctex" path="res://.godot/imported/ballBlue_10.png-83cd69a8a910b68487ca4d42f1af5893.ctex"
metadata={ metadata={
"vram_texture": false "vram_texture": false
} }
[deps] [deps]
source_file="res://assets/ballBlue_10.png" source_file="res://assets/img/ballBlue_10.png"
dest_files=["res://.godot/imported/ballBlue_10.png-a6ac20f1eeff46860499a0f8c7bba4ff.ctex"] dest_files=["res://.godot/imported/ballBlue_10.png-83cd69a8a910b68487ca4d42f1af5893.ctex"]
[params] [params]

View file

@ -11,7 +11,7 @@ config_version=5
[application] [application]
config/name="Godot Docs" config/name="Godot Docs"
run/main_scene="res://scenes/main.tscn" run/main_scene="res://scenes/balls.tscn"
config/features=PackedStringArray("4.3", "Forward Plus") config/features=PackedStringArray("4.3", "Forward Plus")
config/icon="res://icon.png" config/icon="res://icon.png"

View file

@ -1,6 +1,6 @@
[gd_scene load_steps=4 format=3 uid="uid://dm5jrnxmxnuof"] [gd_scene load_steps=4 format=3 uid="uid://dm5jrnxmxnuof"]
[ext_resource type="Texture2D" uid="uid://dv6rx85s1gy3i" path="res://assets/ballBlue_10.png" id="1"] [ext_resource type="Texture2D" uid="uid://dv6rx85s1gy3i" path="res://assets/img/ballBlue_10.png" id="1"]
[sub_resource type="PhysicsMaterial" id="1"] [sub_resource type="PhysicsMaterial" id="1"]
bounce = 0.5 bounce = 0.5

View file

@ -1,8 +1,8 @@
[gd_scene load_steps=13 format=3 uid="uid://coq78ajuagqrq"] [gd_scene load_steps=13 format=3 uid="uid://coq78ajuagqrq"]
[ext_resource type="Script" path="res://scripts/main.gd" id="1"] [ext_resource type="Script" path="res://scripts/balls.gd" id="1"]
[ext_resource type="PackedScene" uid="uid://dm5jrnxmxnuof" path="res://scenes/ball.tscn" id="2"] [ext_resource type="PackedScene" uid="uid://dm5jrnxmxnuof" path="res://scenes/ball.tscn" id="2"]
[ext_resource type="Texture2D" uid="uid://dkq1swbmmxmbq" path="res://assets/Bouncy Platform Long.png" id="3"] [ext_resource type="Texture2D" uid="uid://dkq1swbmmxmbq" path="res://assets/img/Bouncy Platform Long.png" id="3"]
[sub_resource type="PhysicsMaterial" id="1"] [sub_resource type="PhysicsMaterial" id="1"]
bounce = 0.5 bounce = 0.5

19
scenes/button.tscn Normal file
View file

@ -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"]

View file

@ -3,17 +3,19 @@ extends Sprite2D
var speed = 400 var speed = 400
var angular_speed = PI var angular_speed = PI
func _ready():
var timer = get_node("Timer")
timer.timeout.connect(_on_timer_timeout)
func _process(delta: float) -> void: func _process(delta: float) -> void:
var direction = 0 rotation += angular_speed * delta
if Input.is_action_pressed("ui_left"): var velocity = Vector2.UP.rotated(rotation) * speed
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
position += velocity * delta position += velocity * delta
func _on_button_pressed() -> void:
set_process(not is_processing())
func _on_timer_timeout():
visible = not visible