feat: add area2d; connect a bodyEntered and bodyLeft signals to that area2d;

This commit is contained in:
2026-08-18 14:02:19 +02:00
parent ee8c8837d3
commit 4638954cdc
4 changed files with 45 additions and 9 deletions
+15 -1
View File
@@ -3,6 +3,7 @@
[ext_resource type="PackedScene" uid="uid://5viursrnvdyf" path="res://Scenes/Player/player.tscn" id="1_2p8i2"] [ext_resource type="PackedScene" uid="uid://5viursrnvdyf" path="res://Scenes/Player/player.tscn" id="1_2p8i2"]
[ext_resource type="Texture2D" uid="uid://jwfuu6t3ip1f" path="res://Ninja Adventure - Asset Pack/Backgrounds/Tilesets/TilesetFloor.png" id="1_l6yvh"] [ext_resource type="Texture2D" uid="uid://jwfuu6t3ip1f" path="res://Ninja Adventure - Asset Pack/Backgrounds/Tilesets/TilesetFloor.png" id="1_l6yvh"]
[ext_resource type="Texture2D" uid="uid://clv4i0q1nosad" path="res://Ninja Adventure - Asset Pack/Backgrounds/Tilesets/TilesetNature.png" id="2_04h35"] [ext_resource type="Texture2D" uid="uid://clv4i0q1nosad" path="res://Ninja Adventure - Asset Pack/Backgrounds/Tilesets/TilesetNature.png" id="2_04h35"]
[ext_resource type="Script" uid="uid://0a6yl260cuo3" path="res://Scenes/SceneEntrance/scene_entrance.gd" id="4_kr7le"]
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_04h35"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_04h35"]
texture = ExtResource("1_l6yvh") texture = ExtResource("1_l6yvh")
@@ -768,6 +769,8 @@ texture = ExtResource("2_04h35")
physics_layer_0/collision_layer = 1 physics_layer_0/collision_layer = 1
sources/0 = SubResource("TileSetAtlasSource_kr7le") sources/0 = SubResource("TileSetAtlasSource_kr7le")
[sub_resource type="RectangleShape2D" id="RectangleShape2D_bqpwv"]
[node name="GameScene" type="Node2D" unique_id=1235113589] [node name="GameScene" type="Node2D" unique_id=1235113589]
[node name="GrassLayer" type="TileMapLayer" parent="." unique_id=1678501979] [node name="GrassLayer" type="TileMapLayer" parent="." unique_id=1678501979]
@@ -780,10 +783,21 @@ tile_set = SubResource("TileSet_bqpwv")
[node name="ObstabcleLayer" type="TileMapLayer" parent="." unique_id=703817951] [node name="ObstabcleLayer" type="TileMapLayer" parent="." unique_id=703817951]
y_sort_enabled = true y_sort_enabled = true
tile_map_data = PackedByteArray("AAABAP7/AAACAAAAAAD///7/AAACAAAAAAADAP//AAACAAAAAAADAP7/AAACAAAAAAACAAIAAAACAAAAAAAGAP//AAAAAAIAAAA=") tile_map_data = PackedByteArray("AAAIAP7/AAAAAAIAAAAKAP3/AAAAAAIAAAAMAP7/AAAAAAIAAAAIAP//AAAAAAIAAAALAAAAAAAAAAIAAAAIAAEAAAAAAAIAAAALAAIAAAAAAAIAAAACAAQAAAAAAAIAAAAFAAMAAAAAAAIAAAAFAAUAAAAAAAIAAAAHAAMAAAAAAAIAAAAIAAQAAAAAAAIAAAAJAAMAAAAAAAIAAAALAAQAAAAAAAIAAAD///f/AAAAAAIAAAD///j/AAAAAAIAAAD///n/AAAAAAIAAAACAPf/AAAAAAIAAAACAPj/AAAAAAIAAAACAPn/AAAAAAIAAAAAAPr/AAAAAAIAAAAEAPr/AAAAAAIAAAD8//f/AAAAAAIAAAD5//f/AAAAAAIAAAD2//f/AAAAAAIAAADz//f/AAAAAAIAAAD1//b/AAAAAAIAAAD3//b/AAAAAAIAAAD5//b/AAAAAAIAAAD8//b/AAAAAAIAAAABAPb/AAAAAAIAAAAEAPX/AAAAAAIAAAADAPb/AAAAAAIAAAAHAPX/AAAAAAIAAAAKAPX/AAAAAAIAAAANAPb/AAAAAAIAAAANAPf/AAAAAAIAAAANAPj/AAAAAAIAAAANAPz/AAAAAAIAAAANAPv/AAAAAAIAAAA=")
tile_set = SubResource("TileSet_ilnae") tile_set = SubResource("TileSet_ilnae")
[node name="Player" parent="ObstabcleLayer" unique_id=1991398375 instance=ExtResource("1_2p8i2")] [node name="Player" parent="ObstabcleLayer" unique_id=1991398375 instance=ExtResource("1_2p8i2")]
[node name="Camera2D" type="Camera2D" parent="ObstabcleLayer/Player" unique_id=1335060572] [node name="Camera2D" type="Camera2D" parent="ObstabcleLayer/Player" unique_id=1335060572]
zoom = Vector2(5, 5) zoom = Vector2(5, 5)
[node name="SceneEntrance" type="Area2D" parent="." unique_id=1266568511]
position = Vector2(192, -87)
script = ExtResource("4_kr7le")
[node name="CollisionShape2D" type="CollisionShape2D" parent="SceneEntrance" unique_id=398357385]
position = Vector2(-145, 66)
shape = SubResource("RectangleShape2D_bqpwv")
[connection signal="body_entered" from="SceneEntrance" to="SceneEntrance" method="_on_body_entered"]
[connection signal="body_exited" from="SceneEntrance" to="SceneEntrance" method="_on_body_exited"]
+8 -8
View File
@@ -3,10 +3,6 @@
[ext_resource type="Script" uid="uid://duilaa5lwqeup" path="res://Scenes/Player/player.gd" id="1_a3d8c"] [ext_resource type="Script" uid="uid://duilaa5lwqeup" path="res://Scenes/Player/player.gd" id="1_a3d8c"]
[ext_resource type="Texture2D" uid="uid://cjbvc07lh4x1b" path="res://Ninja Adventure - Asset Pack/Actor/Characters/KnightGold/SeparateAnim/Walk.png" id="2_a3d8c"] [ext_resource type="Texture2D" uid="uid://cjbvc07lh4x1b" path="res://Ninja Adventure - Asset Pack/Actor/Characters/KnightGold/SeparateAnim/Walk.png" id="2_a3d8c"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_bqpwv"]
radius = 5.0
height = 10.0
[sub_resource type="AtlasTexture" id="AtlasTexture_a3d8c"] [sub_resource type="AtlasTexture" id="AtlasTexture_a3d8c"]
atlas = ExtResource("2_a3d8c") atlas = ExtResource("2_a3d8c")
region = Rect2(0, 0, 16, 16) region = Rect2(0, 0, 16, 16)
@@ -142,14 +138,18 @@ animations = [{
"speed": 6.0 "speed": 6.0
}] }]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_bqpwv"]
radius = 5.0
height = 10.0
[node name="CharacterBody2D" type="CharacterBody2D" unique_id=1991398375] [node name="CharacterBody2D" type="CharacterBody2D" unique_id=1991398375]
motion_mode = 1 motion_mode = 1
script = ExtResource("1_a3d8c") script = ExtResource("1_a3d8c")
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=129222135]
position = Vector2(0, 3)
shape = SubResource("CapsuleShape2D_bqpwv")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=721334358] [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="." unique_id=721334358]
sprite_frames = SubResource("SpriteFrames_bqpwv") sprite_frames = SubResource("SpriteFrames_bqpwv")
animation = &"move_down" animation = &"move_down"
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=129222135]
position = Vector2(0, 3)
shape = SubResource("CapsuleShape2D_bqpwv")
+21
View File
@@ -0,0 +1,21 @@
extends Area2D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func _on_body_entered(body) -> void:
print("body entered!")
pass # Replace with function body.
func _on_body_exited(body: Node2D) -> void:
print("player left!")
pass # Replace with function body.
@@ -0,0 +1 @@
uid://0a6yl260cuo3