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

34 lines
752 B
GDScript

@tool
class_name P extends CollisionPolygon2D
@export var color: Color = Color.WHITE:
set(v):
color = v
update_polygon()
get():
return color
var polygon_2d: Polygon2D = null
var light_occluder_2d: LightOccluder2D = null
@export var update: bool:
set(v):
update_polygon()
func update_polygon():
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
# light occluder
var lo_polygon = OccluderPolygon2D.new()
lo_polygon.polygon = polygon
light_occluder_2d.occluder = lo_polygon
func _ready() -> void:
update_polygon()