summaryrefslogtreecommitdiff
path: root/Objects
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-05-11 16:13:23 +0200
committerDaniel Weipert <git@mail.dweipert.de>2024-05-11 16:13:23 +0200
commit7f3caaf1a254880b86bb4706f36505514c0a24d4 (patch)
tree501b66530c6a839dd74ff7a4a9a64086311773c5 /Objects
parent17716f198bf6b3e4d39d48d0394192a5cb640499 (diff)
use Area2D signals instead of _process overlap check
Diffstat (limited to 'Objects')
-rw-r--r--Objects/BuilderObject.gd23
-rw-r--r--Objects/BuilderObject.tscn2
2 files changed, 11 insertions, 14 deletions
diff --git a/Objects/BuilderObject.gd b/Objects/BuilderObject.gd
index 9131120..04ff0b8 100644
--- a/Objects/BuilderObject.gd
+++ b/Objects/BuilderObject.gd
@@ -2,8 +2,6 @@ class_name BuilderObject
extends Node2D
-signal collided
-
var is_colliding = false
var is_dragged = false
@@ -12,18 +10,8 @@ var last_position = Vector2(0,0)
func _process(_delta):
- if $Area2D.get_overlapping_areas().size() > 0:
- is_colliding = true
- else:
- is_colliding = false
-
if is_dragged:
position = get_global_mouse_position() + mouse_offset
-
- if is_colliding:
- modulate = Color("bb5a4b")
- else:
- modulate = Color("fff")
func _on_area_2d_input_event(_viewport, event: InputEvent, _shape_idx):
@@ -48,3 +36,14 @@ func drag_end():
queue_free()
is_dragged = false
+
+
+func _on_area_2d_area_entered(_area):
+ is_colliding = true
+ modulate = Color("bb5a4b")
+
+
+func _on_area_2d_area_exited(_area):
+ if $Area2D.get_overlapping_areas().size() == 0:
+ is_colliding = false
+ modulate = Color("fff")
diff --git a/Objects/BuilderObject.tscn b/Objects/BuilderObject.tscn
index ad83377..aae66c7 100644
--- a/Objects/BuilderObject.tscn
+++ b/Objects/BuilderObject.tscn
@@ -23,6 +23,4 @@ region_rect = Rect2(2, 13, 60, 49)
[connection signal="area_entered" from="Area2D" to="." method="_on_area_2d_area_entered"]
[connection signal="area_exited" from="Area2D" to="." method="_on_area_2d_area_exited"]
-[connection signal="area_shape_entered" from="Area2D" to="." method="_on_area_2d_area_shape_entered"]
-[connection signal="area_shape_exited" from="Area2D" to="." method="_on_area_2d_area_shape_exited"]
[connection signal="input_event" from="Area2D" to="." method="_on_area_2d_input_event"]