diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-12-01 21:19:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-01 21:19:30 +0100 |
commit | 1c5a8894aa450876447764037af852f97238d9c0 (patch) | |
tree | ee3f80513e557794627097636583641d16835e03 /scene/2d | |
parent | b9d877e55fc469e7441cb00856359946b91d00ff (diff) | |
parent | 6db29583f2a970cfd8b8409e2f7ff3764a9aa1fd (diff) |
Merge pull request #55516 from lawnjelly/path_2d_polyline_4
Diffstat (limited to 'scene/2d')
-rw-r--r-- | scene/2d/path_2d.cpp | 14 | ||||
-rw-r--r-- | scene/2d/path_2d.h | 1 |
2 files changed, 9 insertions, 6 deletions
diff --git a/scene/2d/path_2d.cpp b/scene/2d/path_2d.cpp index ed30e871d7..40211f2a9b 100644 --- a/scene/2d/path_2d.cpp +++ b/scene/2d/path_2d.cpp @@ -100,16 +100,18 @@ void Path2D::_notification(int p_what) { #endif const Color color = Color(0.5, 0.6, 1.0, 0.7); - for (int i = 0; i < curve->get_point_count(); i++) { - Vector2 prev_p = curve->get_point_position(i); + _cached_draw_pts.resize(curve->get_point_count() * 8); + int count = 0; - for (int j = 1; j <= 8; j++) { - real_t frac = j / 8.0; + for (int i = 0; i < curve->get_point_count(); i++) { + for (int j = 0; j < 8; j++) { + real_t frac = j * (1.0 / 8.0); Vector2 p = curve->interpolate(i, frac); - draw_line(prev_p, p, color, line_width); - prev_p = p; + _cached_draw_pts.set(count++, p); } } + + draw_polyline(_cached_draw_pts, color, line_width, true); } } diff --git a/scene/2d/path_2d.h b/scene/2d/path_2d.h index 3b12f025fc..7e8478283f 100644 --- a/scene/2d/path_2d.h +++ b/scene/2d/path_2d.h @@ -38,6 +38,7 @@ class Path2D : public Node2D { GDCLASS(Path2D, Node2D); Ref<Curve2D> curve; + Vector<Vector2> _cached_draw_pts; void _curve_changed(); |