How to define OccluderPolygon2D in code

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By hard

I am using this code

var shape: PoolVector2Array  = [Vector2(0,0), Vector2(0,70), Vector2(70,0), Vector2(70,70)]
set_occluder_polygon(shape)

which gives error because of not having same type. I used this because OccluderPolygon2D has PoolVector2Array Polygon

:bust_in_silhouette: Reply From: matheusmdx

You need create a new OccluderPolygon2D resource and in this new resource you pass the PoolVector2Array with the points

var light_occluder = LightOccluder2D.new()
add_child(light_occluder)
var occluder_polygon = OccluderPolygon2D.new()
occluder_polygon.polygon = PoolVector2Array([Vector2(0,0), Vector2(0,70), Vector2(70,0), Vector2(70,70)])
light_occluder.set_occluder_polygon(occluder_polygon)