This repository has been archived on 2025-09-28. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
rectangular/core/polygon/polygon.gd

35 lines
752 B
GDScript3
Raw Normal View History

2024-09-25 21:18:58 +02:00
@tool
2024-10-16 20:23:53 +02:00
class_name P extends CollisionPolygon2D
2024-09-25 21:18:58 +02:00
@export var color: Color = Color.WHITE:
set(v):
color = v
update_polygon()
get():
return color
2024-10-16 20:23:53 +02:00
var polygon_2d: Polygon2D = null
var light_occluder_2d: LightOccluder2D = null
2024-09-25 21:18:58 +02:00
@export var update: bool:
set(v):
update_polygon()
func update_polygon():
2024-10-16 20:23:53 +02:00
if polygon_2d == null:
polygon_2d = Polygon2D.new()
self.add_child(polygon_2d)
if light_occluder_2d == null:
light_occluder_2d = LightOccluder2D.new()
self.add_child(light_occluder_2d)
# visible polygon
polygon_2d.polygon = polygon
polygon_2d.color = color
2024-09-26 20:10:56 +02:00
# light occluder
var lo_polygon = OccluderPolygon2D.new()
lo_polygon.polygon = polygon
2024-10-16 20:23:53 +02:00
light_occluder_2d.occluder = lo_polygon
2024-09-25 21:18:58 +02:00
func _ready() -> void:
update_polygon()