From f5593483ba906b66779cb4466a7f2c5b2ed004a8 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sun, 12 May 2024 12:38:10 +0200 Subject: screen drag + visible object collision shapes --- Objects/BuilderObject.gd | 10 +++++++--- Objects/BuilderObject.tscn | 14 +++++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) (limited to 'Objects') diff --git a/Objects/BuilderObject.gd b/Objects/BuilderObject.gd index 04ff0b8..2be50da 100644 --- a/Objects/BuilderObject.gd +++ b/Objects/BuilderObject.gd @@ -9,6 +9,10 @@ var mouse_offset = Vector2(0,0) var last_position = Vector2(0,0) +func _ready(): + $CollisionShape.texture.width = $Area2D/CollisionShape2D.shape.size.x + + func _process(_delta): if is_dragged: position = get_global_mouse_position() + mouse_offset @@ -44,6 +48,6 @@ func _on_area_2d_area_entered(_area): func _on_area_2d_area_exited(_area): - if $Area2D.get_overlapping_areas().size() == 0: - is_colliding = false - modulate = Color("fff") + #if $Area2D.get_overlapping_areas().size() == 0: + is_colliding = false + modulate = Color("fff") diff --git a/Objects/BuilderObject.tscn b/Objects/BuilderObject.tscn index aae66c7..749ad2a 100644 --- a/Objects/BuilderObject.tscn +++ b/Objects/BuilderObject.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=4 format=3 uid="uid://p0ay1mp7v772"] +[gd_scene load_steps=6 format=3 uid="uid://p0ay1mp7v772"] [ext_resource type="Script" path="res://Objects/BuilderObject.gd" id="1_wjk1m"] [ext_resource type="Texture2D" uid="uid://dfjrmruj2mk0n" path="res://Assets/wooden_bench/32x32/bench-wood.png" id="2_hvvj8"] @@ -6,6 +6,13 @@ [sub_resource type="RectangleShape2D" id="RectangleShape2D_vqo4b"] size = Vector2(80, 64) +[sub_resource type="Gradient" id="Gradient_yqbes"] +offsets = PackedFloat32Array(0, 0.753247) +colors = PackedColorArray(0.236458, 0.753008, 0.820768, 1, 0.755346, 0.317619, 0.61568, 1) + +[sub_resource type="GradientTexture2D" id="GradientTexture2D_lc0p3"] +gradient = SubResource("Gradient_yqbes") + [node name="BuilderObject" type="Node2D"] script = ExtResource("1_wjk1m") @@ -16,6 +23,11 @@ collision_mask = 3 [node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] shape = SubResource("RectangleShape2D_vqo4b") +[node name="CollisionShape" type="Sprite2D" parent="."] +self_modulate = Color(1, 1, 1, 0.490196) +position = Vector2(-1.90735e-06, 0) +texture = SubResource("GradientTexture2D_lc0p3") + [node name="Sprite2D" type="Sprite2D" parent="."] texture = ExtResource("2_hvvj8") region_enabled = true -- cgit v1.2.3