summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2019-04-05 15:44:14 +0200
committerGitHub <noreply@github.com>2019-04-05 15:44:14 +0200
commit434b73bc576ae7e6752c065137d702f3b3cfe085 (patch)
tree9f2be8f37998f17afb79806af65564d197be8644
parentb2fcb405220cae594343c1f9dcd2f0082f1ba717 (diff)
parent61b22beeae31590fc726cb593252c6fa5edc13d5 (diff)
Merge pull request #27240 from Chaosus/clear_line_points
Added method to clear all points in Line2D
-rw-r--r--doc/classes/Line2D.xml7
-rw-r--r--scene/2d/line_2d.cpp10
-rw-r--r--scene/2d/line_2d.h2
3 files changed, 19 insertions, 0 deletions
diff --git a/doc/classes/Line2D.xml b/doc/classes/Line2D.xml
index 66d54b7d9e..7efaf2b55f 100644
--- a/doc/classes/Line2D.xml
+++ b/doc/classes/Line2D.xml
@@ -20,6 +20,13 @@
Add a point at the [code]position[/code]. Appends the point at the end of the line.
</description>
</method>
+ <method name="clear_points">
+ <return type="void">
+ </return>
+ <description>
+ Removes all points from the line.
+ </description>
+ </method>
<method name="get_point_count" qualifiers="const">
<return type="int">
</return>
diff --git a/scene/2d/line_2d.cpp b/scene/2d/line_2d.cpp
index 105eb82afb..73692e0535 100644
--- a/scene/2d/line_2d.cpp
+++ b/scene/2d/line_2d.cpp
@@ -112,6 +112,14 @@ int Line2D::get_point_count() const {
return _points.size();
}
+void Line2D::clear_points() {
+ int count = _points.size();
+ if (count > 0) {
+ _points.resize(0);
+ update();
+ }
+}
+
void Line2D::add_point(Vector2 pos) {
_points.append(pos);
update();
@@ -313,6 +321,8 @@ void Line2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_point", "position"), &Line2D::add_point);
ClassDB::bind_method(D_METHOD("remove_point", "i"), &Line2D::remove_point);
+ ClassDB::bind_method(D_METHOD("clear_points"), &Line2D::clear_points);
+
ClassDB::bind_method(D_METHOD("set_width", "width"), &Line2D::set_width);
ClassDB::bind_method(D_METHOD("get_width"), &Line2D::get_width);
diff --git a/scene/2d/line_2d.h b/scene/2d/line_2d.h
index 5bbd38e460..32befab2d3 100644
--- a/scene/2d/line_2d.h
+++ b/scene/2d/line_2d.h
@@ -70,6 +70,8 @@ public:
int get_point_count() const;
+ void clear_points();
+
void add_point(Vector2 pos);
void remove_point(int i);