Added method to clear all points in Line2D

(cherry picked from commit 61b22beeae)
This commit is contained in:
Chaosus 2019-03-19 19:59:24 +03:00 committed by Hein-Pieter van Braam-Stewart
parent 759c1fb0b8
commit 4f3fc559bc
3 changed files with 19 additions and 0 deletions

View file

@ -18,6 +18,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>

View file

@ -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);

View file

@ -70,6 +70,8 @@ public:
int get_point_count() const;
void clear_points();
void add_point(Vector2 pos);
void remove_point(int i);