Right click your one of your folders in the File System
section of your editor New Resource -> ConvexPolygonShape2D or ConcavePolygonShape2D
. Define your polygon in the editor per usual and save the resource. Use a CollisionShape2D
not a CollisionPolygon2D
and load the polygon resource you created. In code you're probably going to need to do something like this:
var sprite_polygon_dictionary = {}
onready var my_sprite = $Sprite
onready var my_collision_shape = $CollisionShape2D
func load_sprite_dictionary(sprite_texture_array, polygon_paths_array):
for index in range(sprite_texture_array.size()):
sprite_polygon_dictionary[sprite_texture_array[index]] = load(polygon_paths_array[index])
func change_to_sprite(sprite):
var polygon = sprite_polygon_dictionary.get(sprite)
if polygon:
my_sprite.set_texture(sprite)
my_collision_shape.set_shape(polygon)