+4 votes

Is it possible to have a Polygon2D with outline?

in Engine by (177 points)

2 Answers

+11 votes
Best answer

Here the little script I made for this.

tool
extends Polygon2D

export(Color) var OutLine = Color(0,0,0) setget set_color
export(float) var Width = 2.0 setget set_width

func _draw():
    var poly = get_polygon()
    for i in range(1 , poly.size()):
        draw_line(poly[i-1] , poly[i], OutLine , Width)
    draw_line(poly[poly.size() - 1] , poly[0], OutLine , Width)

func set_color(color):
    OutLine = color
    update()

func set_width(new_width):
    Width = new_width
    update()
by (177 points)
selected by
+4 votes

You could create a script with a draw function, which reads out the polygon segments and draws a line with a certain thickness and color for each.

by (199 points)

Thanks, this is a good answer. For some reason I was trying to find another way.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.